| Contents | Index |
if expression statements elseif expression statements else statements end
An if statement evaluates an expression, and executes a group of statements when the expression is true.
elseif and else are optional, and execute only when previous expressions in the if statement are false.
For more information about valid expressions and when they are true, see the if reference page.
Find the indices of values in a vector that are greater than a specified limit:
A = rand(1,10);
limit = .75;
B = (A > limit); % B is a vector of logical values
if any(B)
fprintf('Indices of values > %4.2f: \n', limit);
disp(find(B))
else
disp('All values are below the limit.')
endend | for | if | switch | while

Explore how to use MATLAB to make advancements in engineering and science.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |