顺序结构语句
hold on的使用
>> clear all;
>> a=[15 21 26 32 38];
>> b=[99.5 100 100.6 101.2 103.1];
>> figure;
>> plot(a,b);hold on;plot(a,b,'ro');
分支控制语句
- if与else或elseif连用,偏向于是非选择,当某个逻辑条件满足时执行if后的语句,否则执行else语句。
>>clear all;
>> nrows=4;
>> ncols=6;
>> A=ones(nrows,ncols);
>> for c=1:ncols
for r=1:nrows
if r==c
A(r,c)=2;
elseif abs(r-c)==1
A(r,c)=-1;
else
A(r,c)=0;
end