第2章Maab语言程序设计 4、程序结构与流程控制语句 a)顺序结构 程序模块1 新程序模块 程序模块2
第2章 Matlab语言程序设计 4、程序结构与流程控制语句 a) 顺序结构
第2章Maab语言程序设计 b)条件结构 逻辑表达式 程序模块1; 不成立 条件 程序模块2; 成立 新程序模块 d 或 程序模块1 程序模块2 i逻辑表达式 程序模块1; end if-lse-end语句
b) 条件结构 if- else- end 语句 第2章 Matlab语言程序设计 或
第2章Maab语言程序设计 2x2+1 > >绘出函数y=210 1<x<1 的图像。 折扣问题 x<1 > book20 p>x=-3:0.1:3; >>number=40 + No.1 ifx>=1 File Edt yew Insert Tools Window Help > sums=0.0 y=2*x^2+1; →舀)Ax/pp >>if number>=30 plot(x,y) sums=book*number*0.7 elseif-1<x<1 > sums plot(x, y) sums el 560 plot(x, y end
折扣问题 >> book=20; >> number=40; >> sums=0.0; >> if number>=30 sums=book*number*0.7; end >> sums sums = 560 绘出函数 的图像。 >> x=-3:0.1:3; >> if x>=1 y=2*x.^2+1; plot(x,y) elseif -1<x<1 y=5; plot(x,y) else y=-x.^3; plot(x,y) end − − + = 1 0 1 1 2 1 1 3 2 x x x x x y 第2章 Matlab语言程序设计
第2章Maab语言程序设计 switch<表达式> 计算整型表达 Cae<数值1> 模块1; cae<数值2> 表达式的值等于? 模块2; 数值1 数值 数值3 其它 otherwise 模块1模块2模块3 模块n end switch语句
switch语句 第2章 Matlab语言程序设计
第2章Maab语言程序设计 多项选择 >No=input(Please input your choice! Please input your choice! 1 itch N case 0 dispc'return to main menu) disp('she is a girl,) case 2 dische is a boy) dispel can"t determine,) end She is a girl
第2章 Matlab语言程序设计 多项选择 >> No=input('Please input your choice! '); Please input your choice! 1 >> switch No case 0 disp('return to main menu'); case 1 disp('She is a girl'); case 2 disp('He is a boy'); otherwise disp('I can''t determine') end She is a girl