DSP Using Matlab® - 3
DSP Using Matlab® - 3
Equal to (==)
if guess ~= number
fprintf(‘Haha! Your guess was wrong.\n');
fprintf('The number i was thinking of was %g. \n');
end
Control Flow
Example program – Guessing Game.
>> guess01
I am thinking of a number between 1 and 10.
Guess a number: 5
Haha!. Your guess was wrong.
The number i was thinking of was 1.
switch command
case 1
statement 1;
case 2
statement 2;
case {3,4,5}
fprintf(‘Your chose either option 3,4 or 5.’)
statement 3;
otherwise
fprintf(‘Error! – Please choose 1 – 5 only!’)
end
Control Flow
FOR loops and BREAK
Used to execute a set of statements (m) a
particular number of times (n).