创建分节符:%%,执行程序的时候每个节独立运行
断点调试程序
Relation opearters关系逻辑运算符
< <= > >= == ~=
&& and
|| or
logic shrtcut逻辑短路
逻辑短路与“与”操作: 在一个“与”操作中,如果第一个条件为假(False),那么整个表达式的值就会是假,而无论后面的条件是什么,后面的条件将不再被计算。
逻辑短路与“或”操作: 在一个“或”操作中,如果第一个条件为真(True),那么整个表达式的值就会是真,而无论后面的条件是什么,后面的条件将不再被计算。
a=30;
b=4;
c=2;(a>b)||(b==2)
(a>b)&&(b==2)a=[1 2 3]
b=[0 2 3]
a&b
||用于逻辑标量
|用于逻辑标量,也可用于数组value对比
if elseif else
a=3
if rem(a,2)==0
disp("a is even")
elseif rem(a,2)~=0
disp('a is odd')
else
disp('也可以不写elseif在这个例子中')
end
for
for n=1:10
a(n)=2^n;%直接创建数组索引
end
disp('a array is')
disp(a)
for例子2
tic
toc
计时器函数
tic
A=zeros(10,10)
for ii=1:size(A,1);
for jj=1:size(A,2);
A(ii,jj)=ii+jj;
end
end
A
toc
while
help prod;
n=1
while prod(1:n)<1e100
n=n+1
end
1e100=1*10^(100)
prod(1:n)=n!
switch case otherwise
input_num=7;
switch input_num
case 1
disp('1')
case 2
disp('2')
case 7
disp('7 haha')
otherwise
disp('no at all')
end
try catch 略
break terminate the loop of for or while
与while/for有关伪代码:
while exxor?error_threshold
if k>100
break
x=x-sin(x)
k=k+1
end
end
continue
pass control to next iteration loop of for or while
其他
end [1]last array index [2]terminate the block
pause halt execution temporarily
return return control to invoking function