当前位置:网站首页>捡起MATLAB的第(4)天
捡起MATLAB的第(4)天
2022-04-23 15:54:00 【Sola_Ex】
Matlab
if的使用
if 条件
esleif 条件
....
else
end
switch的使用
switch 变量
case 条件1
执行任务1
case 条件2
执行任务2
....
otherwise
执行别的
end
输入语句
X = input('message') %输入数据格式
X = input('message','s') %输入字符串格式
注:里面的massage可以写别的内容,如:请输出xxx。数据格式中,使用字符串会出现报错。字符串是支持中文输入的。
输出语句
disp()
个人觉得这个disp()的命令挺有意思,格式丰富多彩,如:
disp('许佬非常牛逼') %直接打印字符
disp(['彭',['佬'],['也很牛逼'])
disp(666)
disp(['许佬',num2str(666)]) %打印效果,许佬 666
格式化输出:

fprintf(formatSpace,A) %formatSpace是格式类型,A是输出内容
如:
fprintf('许佬 long %d\n cm',14) %效果:许佬 long 14 cm
fprintf('桂佳 long %4.1f\n cm',5.1) %效果:桂佳 long 5.1 cm
其实这跟C语言的很像。
for循环
for 循环控制变量 = 变量范围
执行语句
end
如:
for a=10:20
fprintf('value is %d\n',a)
end
最后的结果是打印10-20的所有整数(步长为1)
while循环
while 判断条件
执行语句
end
注意:while里的判断条件,其实个if里面的一样。
break与continue
break的使用,如:
while true
....
if 条件满足
break;
end
end
if里面的break直接退出while循环,
continue的使用,如:
while true
....
if 条件满足
continue;
end
end
作用是退出本次的while循环,然后继续下一次的while。
特别提醒:
在matlab中,不管是通过脚本(.m文件)还是直接在cmd windows下执行的while,如果while一直处于循环,而你又想停下来,可以直接按ctrl +c强制停止运行。(老子算到电脑蓝屏了)
版权声明
本文为[Sola_Ex]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_42312125/article/details/107476997
边栏推荐
猜你喜欢

Temporal model: long-term and short-term memory network (LSTM)
![Merging of Shanzhai version [i]](/img/e7/f301697aea879bcad8cef70ca890cc.png)
Merging of Shanzhai version [i]

C language --- string + memory function

现在做自媒体能赚钱吗?看完这篇文章你就明白了

IronPDF for . NET 2022.4.5455

MySQL集群模式與應用場景

Filter usage of spark operator

MySQL optimistic lock to solve concurrency conflict

多级缓存使用

C#,贝尔数(Bell Number)的计算方法与源程序
随机推荐
大厂技术实现 | 行业解决方案系列教程
js正則判斷域名或者IP的端口路徑是否正確
Named in pytoch_ parameters、named_ children、named_ Modules function
王启亨谈Web3.0与价值互联网“通证交换”
How do you think the fund is REITs? Is it safe to buy the fund through the bank
Cap theorem
The biggest winner is China Telecom. Why do people dislike China Mobile and China Unicom?
C language self compiled string processing function - string segmentation, string filling, etc
PS add texture to picture
Spark 算子之distinct使用
Leetcode-374 guess the size of the number
Go concurrency and channel
Spark 算子之sortBy使用
C, calculation method and source program of bell number
Partitionby of spark operator
gps北斗高精度卫星时间同步系统应用案例
Tencent offer has been taken. Don't miss the 99 algorithm high-frequency interview questions. 80% of them are lost in the algorithm
MetaLife与ESTV建立战略合作伙伴关系并任命其首席执行官Eric Yoon为顾问
s16. One click installation of containerd script based on image warehouse
Single architecture system re architecture