[信息与通信]第三章 matlab程序设计.pdfVIP

  • 3
  • 0
  • 约2.91万字
  • 约 57页
  • 2018-03-01 发布于浙江
  • 举报
[信息与通信]第三章 matlab程序设计

Matlab and Engineering Calculation Matlab and Engineering Calculation 第3章 MATLAB程序设计 3.1 M文件 3.2 程序控制结构 3.3 函数及函数文件 3.4 Matlab 的文件操作 3.5 程序调试 Xiamen University Xiamen University Matlab and Engineering Calculation Matlab and Engineering Calculation 3.1 M文件 3.1.1 M文件概述 用MATLAB语言编写的程序,称为M文件。 M文件可以根据调用方式的不同分为两类: 命令文件(Script File) 函数文件(Function File) Xiamen University Xiamen University Matlab and Engineering Calculation Matlab and Engineering Calculation 例3-1 分别建立命令文件和函数文件,将华氏温度f 转换为摄氏温度c 。 程序1: 首先建立命令文件并以文件名f2c.m存盘。 clear; %清除工作空间中的变量 f=input(Input Fahrenheit temperature:); c=5*(f-32)/9 然后在MATLAB 的命令窗口中输入f2c,将会执行该 命令文件,执行情况为: Input Fahrenheit temperature :73 c = 22.7778 Xiamen University Xiamen University Matlab and Engineering Calculation Matlab and Engineering Calculation 程序2 : 首先建立函数文件ftoc.m 。 function c=ftoc(f) c=5*(f-32)/9; 然后在MATLAB 的命令窗口调用该函数文件。 clear; y=input(Input Fahrenheit temperature :); x=ftoc(y) 输出情况为: Input Fahrenheit temperature :70 c = 21.1111 x = 21.1111 Xiamen University Xiamen University Matlab and Engineering Calculation Matlab and Engineering Calculation 3.1.2 M文件的建立与打开 M文件是一个文本文件,它可以用任何编辑程序来建立和 编辑,而一般常用且最为方便的是使用MA

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档