Matlab 模块化编程
练习1:
%moduler program
radius = readRadius;area = calclearea(radius);printfarea(radius,area);function radius=readRadius()disp('Please enter the radius in inches.');radius=input('Enter the radius: ');while radius<0disp('Please enter the radius in inches.');radius=input('The number is wrong .please enter the radius again: ');endfprintf('Ok! \n');
endfunction area = calclearea(radius)area=pi*radius^2;
endfunction printfarea(radius,area)fprintf('For a circle with a radius of %.2f inches \n',radius);fprintf('The circle area of %.2f \n',area);
end
练习2:
% Call a function eoption to display the menu and return the uses choice% Call a function explaine to print an expanation of e .% Call a function expfn that will prompt the user for x and print
% both value of built in exp(x) and an aproximnae value for exp(x)choice=eoption()while coice~=4switch choicecase 1explaine;case 2 limite;case 3expfn;endchoice=eoption();endfunction choice=eoption()peintChoices;choice =input('choice :\n')while ~ismember(choice,1:4)peintChoices;choice=input('chioce input again \n');endfunction peintChoices()fprintf('explane 1 explanation \n');fprintf('explane 2 limit \n');fprintf('explane 3 Exponential function \n');fprintf('explane 4 Exit program \n');endend function explaine()fprintf('explane 1\n');
fprintf('explane 2\n');
fprintf('explane 3\n');
fprintf('explane 4\n');
endfunction limite()posum=input('enter a number : \n');while posum<=0fprintf('wrong ,again \n');posum=input('enter a number : \n');endfprintf('An approximation of e with n= %.2f is %.2f \n',posum,(1+1/posum)^posum);
endfunction expfn()x=input('e x : \n');
fprintf('The exact value exp(x) = %.6f\n',exp(x));endfunction y=appExp(x)y=sum(x^(0:(n-1))./factorial(0:(n-1)));
end
persistent 定义变量如何使用:只有在函数里面可以使用这个关键字
function myfunc3()persistent count;if isempty(count)count=0;endcount=count+1;fprintf('The value of count si %d \n',count);
end
>> myfunc3
The value of count si 1
>> myfunc3
The value of count si 2
>>
>> myfunc3
The value of count si 3
>> myfunc3
The value of count si 4
>> clear myfunc3
>> myfunc3
The value of count si 1
全局变量: global
>> global g
>> g=19g =19>> myfunc_global
The global value g is 19.000000
>> // 函数function myfunc_global()
global g;
fprintf('The global value g is %f \n',g);
end
Matlab 模块化编程相关推荐
- matlab模块化编程,DSP2812基于MATLAB模块化编程的SPWM调制实现.pdf
[实例简介] DSP2812基于MATLAB模块化编程的SPWM调制实现 58 32 Simulink func- tion builder SCI S-Function Builder B DSP ...
- matlab两个多项式相除,C++和MATLAB混合编程求解多项式系数(矩阵相除)
摘要:MATLAB对于矩阵处理是非常高效的,而C++对于矩阵操作是非常麻烦的,因而可以采用C++与MATLAB混合编程求解矩阵问题. 主要思路就是,在MATLAB中编写函数脚本并使用C++编译为dll ...
- 怎样用matlab打开mw文,C# matlab混合编程 MWArray使用笔记
C# matlab混合编程 徐凯Email:xukai19871105@http://www.doczj.com/doc/1a6e191fff00bed5b9f31dbf.html 这几天突然想搞一搞 ...
- vc与matlab联合,浅析VC与Matlab联合编程(二) - VC知识库文章
浅析VC与Matlab联合编程(二) 作者:邓科 下载源代码 在"浅析VC与Matlab联合编程 (一)"中简单介绍了VC与matcom的接口编程,实现了VC调用matcom的一个 ...
- (转)Javascript模块化编程(一):模块的写法
转自 ruanyifeng 系列目录: Javascript模块化编程(一):模块的写法 Javascript模块化编程(二):AMD规范 Javascript模块化编程(三):Require.js的 ...
- Javascript模块化编程(一):模块的写法
随着网站逐渐变成"互联网应用程序",嵌入网页的Javascript代码越来越庞大,越来越复杂. 网页越来越像桌面程序,需要一个团队分工协作.进度管理.单元测试等等......开发者 ...
- c 使用matlab引擎,[转载]C与MATLAB混合编程之调用MATLAB引擎
Visual Studio调用MATLAB需要的配置已经在<Visual Studio调用MATLAB的配置>一文中给出了详细的步骤,本文将介绍混合编程的示例. 在C中调用MATLAB,据 ...
- matlab面向对象排序,matlab面向对象编程基础
matlab面向对象编程基础 觉得有用的话,欢迎一起讨论相互学习~ Matlab面向对象大体结构 类定义的普通模板 代码清单2.1.1 classdef className properties pr ...
- keil c语言模块化编程,keil C模块化编程总结
昨晚看了下模块化编程的东西,把自己的工程整了整,可惜没成功.今早发神经似的起床敲代码,很快就发现了错误,原来是条件宏定义的头文件名忘改了,汗!!! 整理下模块化编程的要点,感谢以下三位UP主的帖子: ...
最新文章
- 极致真实感受 无边硬屏即将登场
- Hibernate- QBC-基本查询
- C++语言第一课的学习
- java程序员学习路线以及我的学习经验
- Python脚本生成单个EXE文件
- NoSQL和Redis简介及Redis在Windows下的安装和使用教程
- How to create a angular2 project process
- 计算机应用基础专科在线考试,电子科技大学在线考试2019年春计算机应用基础专科(18页)-原创力文档...
- Ansys Lumerical Zemax Speos | CMOS 传感器相机:3D 场景中的图像质量分析
- oracle获取字符串长度函数length()和hengthb()
- Sybase ASE 12.5.4数据库安装备份还原操作步骤
- tween.js简介
- 宇宙也能测量,破解未解之谜的三维地图出炉
- flink任务优化总结
- EKL语言的核心语法
- 通过access口加vlan标签吗_[转载]vlan与trunk打标签过程
- java web聊天室论文_基于javaweb聊天室.doc
- alertmanager钉钉报警
- MySQL重启卡住_mysql 重启的时候卡住了
- 数通基础-STP原理