当前位置:网站首页>捡起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
边栏推荐
- 实现缺省页面
- 幂等性的处理
- APISIX jwt-auth 插件存在错误响应中泄露信息的风险公告(CVE-2022-29266)
- Leetcode-374 guess the size of the number
- [self entertainment] construction notes week 2
- Metalife established a strategic partnership with ESTV and appointed its CEO Eric Yoon as a consultant
- Application of Bloom filter in 100 million flow e-commerce system
- [open source tool sharing] MCU debugging assistant (oscillograph / modification / log) - linkscope
- Do we media make money now? After reading this article, you will understand
- 为啥禁用外键约束
猜你喜欢
随机推荐
One brush 312 - simple repetition set - Sword finger offer 03 Duplicate number in array (E)
Coalesce and repartition of spark operators
pywintypes. com_ Error: (- 2147221020, 'invalid syntax', none, none)
The length of the last word of the string
Go concurrency and channel
新动态:SmartMesh和MeshBox的合作新动向
Go语言切片,范围,集合
Website pressure measurement tools Apache AB, webbench, Apache jemeter
PHP classes and objects
WPS brand was upgraded to focus on China. The other two domestic software were banned from going abroad with a low profile
运维流程有多重要,听说一年能省下200万?
C#,贝尔数(Bell Number)的计算方法与源程序
Open source project recommendation: 3D point cloud processing software paraview, based on QT and VTK
R语言中绘制ROC曲线方法二:pROC包
Basic greedy summary
The principle and common methods of multithreading and the difference between thread and runnable
Deletes the least frequently occurring character in the string
The biggest winner is China Telecom. Why do people dislike China Mobile and China Unicom?
一文读懂串口及各种电平信号含义
Accumulation of applet knowledge points









