- 1、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
MATLAB 7.0从入门到精通;课程主要内容;第7章 程序设计;7.1 脚本和函数;7.1.1 脚本;huitu0程序结果;7.1.2 函数;huitu(1,2,3)程序结果;7.2 M文件的程序结构;7.2.1 顺序结构;jizhi程序结果;7.2.2 循环结构;1、for循环;程序结果; specmat(6)
ans =
1 1 1 1 1 1
1 2 3 4 5 6
1 3 6 10 15 15
1 4 10 10 15 15
1 5 15 15 15 15
1 6 15 15 15 15;用for循环语句需要注意以下事项:
(1)不能在for循环体内重新对循环变量n赋值来终止循环的执行。
(2)for循环可以进行嵌套循环。
(3)循环语句内的“;”可防止中间变量的输出。;2、while循环;程序结果;程序实例;程序结果; while2
Enter the first value:1
Enter the first value:3
Enter the first value:5
Enter the first value:7
Enter the first value:9
Enter the first value:0
Enter the first value:-1
The mean of this data set is:4.166667
The standard deviation is:3.488075
The number of data is:6;7.2.3 分支结构;1、if-else-end选择语句;程序结果;采用plot(x,ff(x))绘分段函数图。
x1=-2:0.01:0;
x2=0.5:0.01:5;
x3=5.01:0.01:10;
x4=10.01:0.01:12;
plot(x1,ff(x1))
hold on
plot(x2,ff(x2))
hold on
plot(x3,ff(x3))
hold on
plot(x4,ff(x4))
grid on;程序结果;MATLAB中的选择语句switch-case-otherwise,是特别让熟悉C等高级语言的用户方便地编写M文件而专门添加的。switch-case-otherwise语句的通用格式如下:
swith expression
case value1
statements1;
...
case valuen
statementsn;
otherwise
statements;
end;其中,switch-expression给出了开关条件,当有case-expression与之匹配时,就执行其后的语句,如果没有case-expression与之匹配,就执行otherwise后面的语句。在执行过程中,只有一个case命令被执行,当执行完命令后,程序就跳出分支结构,执行end下面的语句。
例:fm.m;程序结果;工程实例;程序结果;45 40.7332
50 40.1144
55 38.2767
60 35.2760
65 31.2034
70 26.1828
75 20.3666
80 13.9316
85 7.0732
90 0.0000
Max ranges is 40.7332 at 45 degrees.;图形结果;7.3 程序流控制;1、continue命令;程序结果;2、break命令;程序结果;3、return命令;程序实例;4、echo语句;5、error语句;6、try...catch语句;程序结果;7、input语句;程序结果;8、pause命令;7.4 脚本文件;7.5 函数文件;???谢!;huitu0.m;huitu.m;jizhi.m;for1.m;specmat.m;while1.m;for2.m;while2.m;ff.m;fm.m;ball.m;%显示计算水平距离的列表。
fprintf(Range versus angle theta:\n);
for i=1:5:91
theta=i-1;
fprintf(%2d %8.4f\n,theta,range(i));
end
%计算最大的角度和水平距离。
[maxrange index]=max(range);
maxangle=index-1;
fprintf(\n Max ranges is %8.4f at %2d degrees.\
文档评论(0)