练习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 模块化编程相关推荐

  1. matlab模块化编程,DSP2812基于MATLAB模块化编程的SPWM调制实现.pdf

    [实例简介] DSP2812基于MATLAB模块化编程的SPWM调制实现 58 32 Simulink func- tion builder SCI S-Function Builder B DSP ...

  2. matlab两个多项式相除,C++和MATLAB混合编程求解多项式系数(矩阵相除)

    摘要:MATLAB对于矩阵处理是非常高效的,而C++对于矩阵操作是非常麻烦的,因而可以采用C++与MATLAB混合编程求解矩阵问题. 主要思路就是,在MATLAB中编写函数脚本并使用C++编译为dll ...

  3. 怎样用matlab打开mw文,C# matlab混合编程 MWArray使用笔记

    C# matlab混合编程 徐凯Email:xukai19871105@http://www.doczj.com/doc/1a6e191fff00bed5b9f31dbf.html 这几天突然想搞一搞 ...

  4. vc与matlab联合,浅析VC与Matlab联合编程(二) - VC知识库文章

    浅析VC与Matlab联合编程(二) 作者:邓科 下载源代码 在"浅析VC与Matlab联合编程 (一)"中简单介绍了VC与matcom的接口编程,实现了VC调用matcom的一个 ...

  5. (转)Javascript模块化编程(一):模块的写法

    转自 ruanyifeng 系列目录: Javascript模块化编程(一):模块的写法 Javascript模块化编程(二):AMD规范 Javascript模块化编程(三):Require.js的 ...

  6. Javascript模块化编程(一):模块的写法

    随着网站逐渐变成"互联网应用程序",嵌入网页的Javascript代码越来越庞大,越来越复杂. 网页越来越像桌面程序,需要一个团队分工协作.进度管理.单元测试等等......开发者 ...

  7. c 使用matlab引擎,[转载]C与MATLAB混合编程之调用MATLAB引擎

    Visual Studio调用MATLAB需要的配置已经在<Visual Studio调用MATLAB的配置>一文中给出了详细的步骤,本文将介绍混合编程的示例. 在C中调用MATLAB,据 ...

  8. matlab面向对象排序,matlab面向对象编程基础

    matlab面向对象编程基础 觉得有用的话,欢迎一起讨论相互学习~ Matlab面向对象大体结构 类定义的普通模板 代码清单2.1.1 classdef className properties pr ...

  9. keil c语言模块化编程,keil C模块化编程总结

    昨晚看了下模块化编程的东西,把自己的工程整了整,可惜没成功.今早发神经似的起床敲代码,很快就发现了错误,原来是条件宏定义的头文件名忘改了,汗!!! 整理下模块化编程的要点,感谢以下三位UP主的帖子: ...

最新文章

  1. 极致真实感受 无边硬屏即将登场
  2. Hibernate- QBC-基本查询
  3. C++语言第一课的学习
  4. java程序员学习路线以及我的学习经验
  5. Python脚本生成单个EXE文件
  6. NoSQL和Redis简介及Redis在Windows下的安装和使用教程
  7. How to create a angular2 project process
  8. 计算机应用基础专科在线考试,电子科技大学在线考试2019年春计算机应用基础专科(18页)-原创力文档...
  9. Ansys Lumerical Zemax Speos | CMOS 传感器相机:3D 场景中的图像质量分析
  10. oracle获取字符串长度函数length()和hengthb()
  11. Sybase ASE 12.5.4数据库安装备份还原操作步骤
  12. tween.js简介
  13. 宇宙也能测量,破解未解之谜的三维地图出炉
  14. flink任务优化总结
  15. EKL语言的核心语法
  16. 通过access口加vlan标签吗_[转载]vlan与trunk打标签过程
  17. java web聊天室论文_基于javaweb聊天室.doc
  18. alertmanager钉钉报警
  19. MySQL重启卡住_mysql 重启的时候卡住了
  20. 数通基础-STP原理

热门文章

  1. PHP导出Excel 数字变成科学计数法解决方法
  2. USB Mass Storage协议
  3. 月夜_飘云羽逸_新浪博客
  4. 【Go】面向对象(四):面向对象实战(图书借阅系统demo)
  5. Sklearn——决策树可视化
  6. 用于跑深度学习的嵌入式硬件平台资料整理(二)
  7. 为什么有的站点别人能访问但我无法访问
  8. C#编写简单的人工智能课程的实验-猴子摘香蕉
  9. ansible 和文件复制相关的几个模块(templete和copy的区别)
  10. 投资合伙人股份分配_合伙人形势入股是怎么算股份的?