当前位置:网站首页>捡起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
边栏推荐
- 一文掌握vscode远程gdb调试
- [self entertainment] construction notes week 2
- 贫困的无网地区怎么有钱建设网络?
- Spark 算子之partitionBy
- Website pressure measurement tools Apache AB, webbench, Apache jemeter
- Why is IP direct connection prohibited in large-scale Internet
- Neodynamic Barcode Professional for WPF V11.0
- Go concurrency and channel
- Neodynamic Barcode Professional for WPF V11. 0
- C language --- advanced pointer
猜你喜欢
Spark 算子之sortBy使用
时序模型:门控循环单元网络(GRU)
Implement default page
Configuration of multi spanning tree MSTP
Ice -- source code analysis
大型互联网为什么禁止ip直连
The biggest winner is China Telecom. Why do people dislike China Mobile and China Unicom?
Config组件学习笔记
Partitionby of spark operator
Function summary of drawing object arrangement in R language
随机推荐
Fastjon2 here he is, the performance is significantly improved, and he can fight for another ten years
Unity shader learning
【开源工具分享】单片机调试助手(示波/改值/日志) - LinkScope
Go并发和通道
Basic greedy summary
Modèle de Cluster MySQL et scénario d'application
基于 TiDB 的 Apache APISIX 高可用配置中心的最佳实践
C语言自编字符串处理函数——字符串分割、字符串填充等
Vision of building interstellar computing network
为啥禁用外键约束
Spark 算子之交集、并集、差集
腾讯Offer已拿,这99道算法高频面试题别漏了,80%都败在算法上
[self entertainment] construction notes week 2
Why is IP direct connection prohibited in large-scale Internet
现在做自媒体能赚钱吗?看完这篇文章你就明白了
Interview questions of a blue team of Beijing Information Protection Network
Unity Shader学习
dlopen/dlsym/dlclose的简单用法
js正则判断域名或者IP的端口路径是否正确
糖尿病眼底病变综述概要记录