Graphics Programs Reference
In-Depth Information
sgn=0;
end
>> signum (-1.5)
ans =
-1
switch
The switch construct is
switch expression
case value1
block
case value2
block
.
otherwise
block
end
Here the expression isevaluated and the control is passed to the case thatmatches the
value.Forinstance, if the valueof expression isequalto value2 , the block of statements
following case value2 isexecuted. If the valueof expression does not match any
of the case values, the control passes to the optional otherwise block. Here is an
example:
functiony=trig(func,x)
switch func
case 'sin'
y = sin(x);
case 'cos'
y = cos(x);
case 'tan'
y = tan(x);
otherwise
error('No such function defined')
end
>> trig('tan',pi/3)
ans =
1.7321
Search WWH ::




Custom Search