2.3数学函数 函数使用说明: ■(1)三角函数以弧度为单位计算。 ■(2)abs函数可以求实数的绝对值、复数的模、 字符串的ASCII码值。 (多功能) ■(3)用于取整的函数有fix、f1oor、ceil、 round,要注意它们的区别。 常用的基本数学函数如课本表2.7所示 2015-2-4 1
2015-2-4 1 函数使用说明: (1) 三角函数以弧度为单位计算。 (2) abs函数可以求实数的绝对值、复数的模、 字符串的ASCII码值。 (多功能) (3) 用于取整的函数有fix、floor、ceil、 round,要注意它们的区别。 常用的基本数学函数如课本表2.7所示 2.3 数学函数
PS:数组的信息获取 ◆1.数组的尺寸 函数名 函数描述 size 矩阵或数组各方向的长度 length 矩阵或数组各方向中的最长长度 ndims 矩阵或数组的维数 numel 矩阵或数组的元素个数 ◆2.数组的检测函数 口以“s”开头,函数返回的结果为逻辑型,如果检测符 合条件则返回1,不符合条件就返回0。 isempty,isscalar,isvector,issparse,isnumeric,isreal, isfloat,isinteger,ischar,islogical,iscell,isstruct,isa. 2015-2-4 2
2015-2-4 2 PS :数组的信息获取 1. 数组的尺寸 2. 数组的检测函数 以“is”开头,函数返回的结果为逻辑型,如果检测符 合条件则返回1,不符合条件就返回0。 isempty, isscalar, isvector, issparse, isnumeric, isreal, isfloat, isinteger, ischar, islogical, iscell, isstruct, isa. ndims 矩阵或数组的维数 length 矩阵或数组各方向中的最长长度 numel 矩阵或数组的元素个数 size 矩阵或数组各方向的长度 函数名 函数描述
Logical Functions ◆Function Purpose ischar (a) Returns a 1 if a is a character array and a 0 otherwise. isempty (a) Returns a 1 if a is an empty array and a 0 otherwise. isinf (a) Returns a 1 if the value of a is infinite (Inf) and a 0 otherwise. isnan(a) Returns a 1 if the value of a is NaN (not a number)and a 0 otherwise. isnumeric (a) Returns a l if the a is a numeric array and a 0 otherwise. 2015-2-4 3
2015-2-4 3 Logical Functions Returns a l if the a is a numeric array and a 0 otherwise. isnumeric (a) Returns a 1 if the value of a is NaN (not a number) and a 0 otherwise. isnan (a) Returns a 1 if the value of a is infinite (Inf) and a 0 otherwise. isinf (a) Returns a 1 if a is an empty array and a 0 otherwise. isempty (a) Returns a 1 if a is a character array and a 0 otherwise. ischar (a) Function Purpose
2.4M文件 ◆用MATLAB语言编写的程序,称为M文件。 ◆M文件可以根据调用方式的不同分为两类: 脚本文件(Script File)(也称命令文件) ■函数文件(Function File)。 2015-2-4 4
2015-2-4 4 2.4 M 文件 用MATLAB语言编写的程序,称为M文件。 M文件可以根据调用方式的不同分为两类: 脚本文件(Script File)(也称命令文件) 函数文件(Function File)
2.4.1 脚本文件(Script File) ◆1.建立新的M文件, ■启动MATLAB文本编辑器,即可编写。 ◆2.打开已有的M文件,有3种方法 (1)菜单操作。从MATLAB主窗口的File菜单中选择Open命令, 则屏幕出现Open对话框,在Open对话框中选中所需打开的M文 件。在文档窗口可以对打开的文件进行编辑修改,编辑完成后, 将M文件存盘。 (2)命令操作。在MATLAB命令窗口输入命令:edit文件名, 则打开指定的M文件。 ■ (3)命令按钮操作。单击MATLAB.主窗口工具栏上的Open File 命令按钮,再从弹出的对话框中选择所需打开的M文件。 2015-2-4 5
2015-2-4 5 2.4.1 脚本文件(Script File) 1.建立新的M文件, 启动MATLAB文本编辑器,即可编写。 2.打开已有的M文件,有3种方法 (1) 菜单操作。从MATLAB主窗口的File菜单中选择Open命令, 则屏幕出现Open对话框,在Open对话框中选中所需打开的M文 件。在文档窗口可以对打开的M文件进行编辑修改,编辑完成后, 将M文件存盘。 (2) 命令操作。在MATLAB命令窗口输入命令:edit 文件名, 则打开指定的M文件。 (3) 命令按钮操作。单击MATLAB主窗口工具栏上的Open File 命令按钮,再从弹出的对话框中选择所需打开的M文件