学习笔记(3):MATLAB基础入门课程-for语句

立即学习:https://edu.csdn.net/course/play/5974/112210?utm_source=blogtoedu

B=a+5

B=a-5

B=a*8

B=a/4

 

B=a^2

B=a^(-1)

 

A+b

a-b

 

a*b

 

a/b a*b的逆矩阵

a*inv(b) 数组求逆函数

A*pinv(b) 广义数组求逆函数

a\b a的逆矩阵*b

inv(a)*b

pinv(a)*b

 

a.*b=b.*a

 

a.\b=b./a

 

a.^3

3.^a

a.^b

 

a=true

b=false

a=true(3)

b=false(4)

真:非0的值

假:0

 

>

<

==

>=

<=

~=

5>8

5==5
2~=9

a>b

 

and(3,0)

3&0

And(a,b)

A&b

 

Or(a,b)

A|b

 

非=取反

 Not(a)

~a

 

Xor(a,b) 异或

 

B=any(A)  A为向量、矩阵、[]

B=any(A,dim)

B=any(A,1) 列计算

B=any(A,2) 行计算

 

B=all(A) A为向量、矩阵、[](不存在0)

B= all (A,dim)

B= all (A,1) 列计算

B= all (A,2) 行计算

 

Short-circuit

&& 运算数必须为标量

|| 运算数必须为标量

B=0

X=(b~=0)&&(a/b>18.5)

 

顺序结构、选择结构、循环结构、错误控制结构

Return终止,break,continue,input,error,keyboard,pause

 

If 逻辑表达式1

语句1

Elseif 逻辑表达式2

语句2

Else

语句3

End

 

X赋初始值

If x是偶数

输出“偶数”

End

 

语法格式

X赋初始值

If x是偶数

输出“偶数”

End

 

X=6

If rem(x,2)==0

Disp(‘偶数’)

End

 

A=6

If rem(a,2)==0

Disp(‘even’)

 

A=7

If rem(a,2)==0

Disp(‘even’)

End

If rem(a,2)==1

Disp(‘odd’)

End

 

A=8

If rem(a,2)==0

Disp(‘even’)

Else

Disp(‘odd’)

End

 

a=8

If a>0

disp(‘a>0’)

elseif a==0

disp(‘a=0’)

else

disp(‘a<0’)

end

 

switch 表达式

case 值1

语句1

case 值2

语句2

......

otherwise

语句n

end

 

month=3

switch month

case 3

season=’spring’

case 4

season=’spring’

case 5

season=’spring’

case{6,7,8}

season=’summer’

case{9,10,11}

season=’autumn’

otherwise

season=’winter’

end

元胞数组

month=4;

switch month

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值