SLIDE 3 2017‐07‐24 3
A mo re c o mple x func tio n to c o mpute the are a and the pe rime te r o f a c irc le with a g ive n radius
function [area, perimeter] = circleFun(radius) area = pi*radius^2 perimeter = 2*pi*radius return
– [area, ~] = circleFun(3)
– [~,perimeter] = circleFun(3)
– [area, perimeter] = circleFun(3)
T he branc hing struc ture – if – e lse if - e lse
- MATLAB use the if, elseif, else
statement for flow control
if [logical statement] codes … elseif [logical statement] codes… else codes… end
- We can use the if statement only
- use the if – elseif—else—end
syntax can improve coding efficiency
- The program run from the top to
the bottom, if a true logical statement is found, the program will skip the rest
function