Digital Signal Processing Reference
In-Depth Information
else
sprintf(The indices m and n must be greater than 0.)
end
Also, version 7 of MATLAB was enhanced to allow the && operator to be used
just like in C/C++. (This does not work with version 6.) Here is a short example.
>> array = [37
85
59];
>> index = 3;
>> if (index >=1 ) && (index <= length(array))
array(index) = array(index)+2;
end
>> array
array =
37
85
61
The else statement goes with the nearest if. Note that else if is treated
dierently than elseif. The command else if is treated as two separate state-
ments; an end is expected for both the second if as well as the rst. The command
elseif is a continuation of the rst if, much like a switch/case statement. The
two examples below show how the if statement can be structured.
% One way to structure the if statement
if (a == 1)
sprintf(a = 1)
else if (a == 2)
sprintf(a = 2)
end
end
% Another way to structure the if statement
if (a == 1)
sprintf(a = 1)
elseif (a == 2)
sprintf(a = 2)
end
Search WWH ::




Custom Search