How to get the type of a variable in MATLAB?
MATLAB是否有一个函数/运算符指示变量的类型(类似于JavaScript中的typeof
运算符)?
使用class
功能
>> b = 2
b =
2
>> a = 'Hi'
a =
Hi
>> class(b)
ans =
double
>> class(a)
ans =
char
class()
function is the equivalent of typeof()
You can also use isa()
to check if a variable is of a particular type. If you want to be even more specific, you can use ischar()
, isfloat()
, iscell()
, etc.
Another related function is whos
. It will list all sorts of information (dimensions, byte size, type) for the variables in a given workspace.
>> a = [0 0 7];
>> whos a
Name Size Bytes Class Attributes
a 1x3 24 double
>> b = 'James Bond';
>> whos b
Name Size Bytes Class Attributes
b 1x10 20 char
链接地址: http://www.djcxy.com/p/29268.html
上一篇: MATLAB中的最大数组大小?
下一篇: 如何在MATLAB中获取变量的类型?