当前位置:网站首页>捡起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
边栏推荐
- Spark 算子之coalesce与repartition
- The length of the last word of the string
- Implement default page
- PS为图片添加纹理
- Website pressure measurement tools Apache AB, webbench, Apache jemeter
- 一刷312-简单重复set-剑指 Offer 03. 数组中重复的数字(e)
- Control structure (I)
- 多线程原理和常用方法以及Thread和Runnable的区别
- Go language, condition, loop, function
- Why is IP direct connection prohibited in large-scale Internet
猜你喜欢
MySQL Cluster Mode and application scenario
Metalife established a strategic partnership with ESTV and appointed its CEO Eric Yoon as a consultant
Master vscode remote GDB debugging
Function summary of drawing object arrangement in R language
Codejock Suite Pro v20.3.0
Spark 算子之sortBy使用
Do we media make money now? After reading this article, you will understand
大型互联网为什么禁止ip直连
How important is the operation and maintenance process? I heard it can save 2 million a year?
幂等性的处理
随机推荐
小程序知识点积累
APISIX jwt-auth 插件存在错误响应中泄露信息的风险公告(CVE-2022-29266)
Implement default page
Go concurrency and channel
Go语言数组,指针,结构体
Function summary of drawing object arrangement in R language
WPS brand was upgraded to focus on China. The other two domestic software were banned from going abroad with a low profile
leetcode-396 旋转函数
Read the meaning of serial port and various level signals
Go并发和通道
C, calculation method and source program of bell number
基于 TiDB 的 Apache APISIX 高可用配置中心的最佳实践
Timing model: gated cyclic unit network (Gru)
Spark 算子之sortBy使用
Pgpool II 4.3 Chinese Manual - introductory tutorial
Config组件学习笔记
一刷314-剑指 Offer 09. 用两个栈实现队列(e)
GRBL学习(二)
Redis主从复制过程
pywintypes. com_ Error: (- 2147221020, 'invalid syntax', none, none)