for循环
>>v = zeros(10,1);
>>for i=1:10,
> v(i)=2^i;
> end;
>>v
v =
2
4
8
16
32
64
128
256
512
1024
>>
或者
>> indices = 1:10;
>> for i = indices,
disp(i);
end;
1
2
3
4
5
6
7
8
9
10
>>
while
>>i = 1;
>>while i<=5,
> v(i)=100;
> i = i+1;
> end;
break
>>i = 1;
>>while true,
> v(i) = 999;
> i = i + 1;
> if i==6,
> break;
> end;
> end;
if...else
>>if v(1) == 1,
> disp('The value is one');
> elseif v(1) == 2,
> disp('The value is Two');
> else
> disp('The value is not one or two');
> end;