MATLAB: get variable type

0 votes
asked Feb 23, 2009 by d%c3%b3nal

Does MATLAB have a function/operator that indicates the type of a variable (similar to the typeof operator in JavaScript)?

4 Answers

0 votes
answered Jan 11, 2009 by mike-katz

Be careful when using the isa function. This will be true if your object is of the specified type or one of its subclasses. You have to use strcmp with the class function to test if the object is specifically that type and not a subclass.

0 votes
answered Jan 11, 2009 by gnovice

Another related function is WHOS. It will list all sorts of information (dimensions, byte size, type) for the variables in a given workspace.

0 votes
answered Jan 23, 2009 by dima

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.

0 votes
answered Feb 23, 2009 by daniel-lecheminant

Use the class function

>> b = 2
b =
>> a = 'Hi'
a =
>> class(b)
ans =
>> class(a)
ans =
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter