美文网首页
Octave快速入门(5)——控制语句

Octave快速入门(5)——控制语句

作者: 大锅烩菜 | 来源:发表于2018-09-12 16:01 被阅读0次

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;

相关文章

网友评论

      本文标题:Octave快速入门(5)——控制语句

      本文链接:https://www.haomeiwen.com/subject/nzrvgftx.html