
上QQ阅读APP看本书,新人免费读10天
设备和账号都新为新人
5.4 数组检测
数组结构指的是数组中元素的排列方式,MATLAB中提供了多种检测函数用来判定数组的类型。
5.4.1 isempty()函数
isempty()函数主要用来检测某个数组是否为空数组,其调用形式如下:

其中,A是待检测的数组,如果得到输出参数TF=1,则表示待检测的数组是空数组,否则表示待检测的数组不是空数组。具体示例如下:

5.4.2 isscalar()函数
isscalar()函数主要用来检测某个数组是否为单元素的标量数组,其调用形式如下:

其中,A是待检测的数组,输出的参数是一个逻辑变量,TF=1代表待检测数组只有一个元素,否则为多个元素或空数组。具体示例如下:

5.4.3 isvector()函数
isvector()函数主要用来检测某个数组是否为具有一行元素或一列元素的一维数组,其调用形式如下:

其中,A是待检测的数组,输出参数是一个逻辑变量,TF=1代表待检测的数组是具有一行元素或一列元素的一维数组,否则反之。具体示例如下:

5.4.4 issparse()函数
issparse()函数用来检测某个数组是否为稀疏数组,其调用形式如下:

其中,A是待检测的数组,得到的输出变量是一个逻辑变量,TF=1代表待检测数组为稀疏数组,否则反之。具体示例如下:

本节介绍了数组的多种结构,并给出了检测它们属于什么结构的函数,熟练掌握这些函数,可以帮助用户编写大型 MATLAB 程序,尤其可以帮助用户处理一些技巧性问题。