Matlab and IDL Data Types
14 views (last 30 days)
Show older comments
Hi guys! So I'm having some problems with the data types in Matlab and IDL.
So, in IDL, it automatically identifies the data type of numbers. Like for example, the number -32768 is considered long but when you type this in Matlab, and you put the command "class" or "whos", it's considered as double.
Is there a way in Matlab to figure out the data type the way in IDL?
Thanks a lot!
0 Comments
Answers (1)
Steven Lord
on 30 Jan 2020
The default data type in MATLAB is double.
There are some functions and functionality that by default create variables of different types. Notable among them are true and false which create logical arrays, the conversion functions int8, uint16, etc., and the ability to specify hex literals introduced in release R2019b.
x = 0xbeef % x is a uint16 with value 48879
If you want to know the type of a particular variable use class. If you want to know if a variable is a something, you can use isa (which offers options to check if something is stored as a numeric class, a floating-point class, or an integer class.)
4 Comments
Steven Lord
on 31 Jan 2020
As of release R2016b, according to this entry in the Release Notes, the header information displayed for many data types includes the name of the class of that array. double and char are listed as not displaying that new header, however.
There's no option that I'm aware of to enable that header for double arrays. While you theoretically could overload how double arrays were displayed I would strongly discourage that as it would affect how every double array was displayed and some functions may be depending on the standard display of double arrays.
The general rule of thumb: when you display the contents of a variable, if you don't see that header and it's a number, it's a double.
If you don't see that header and it's text data, it's a char.
If you see that header, it's whatever the header says it is.
Class authors can control how instances of their classes are displayed (which is why that's a rule of thumb and not a rule.)
If you want a function that accepts the number as input and returns the type of the input, you don't need to write your own. The class function built into MATLAB does exactly that. The whos function may also be of interest to you, if you want to get some information (name, class, size, and attributes) about a bunch of variables at once.
See Also
Categories
Find more on Numeric Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!