in this blog post, we will look at most commonly used
data types of matlab, integers and double precision numbers.
I have already told you that double is a basic data type of
matlab. So whatever you do in matlab, if you dont provide the
data type for it, matlab will assume the basic data type of double.
for that variable.
I will briefly introduce you to these data types for I sincerely feel that
you can learn more about them once you start using them and ofcourse,
this blog is no way a substitute to the matlab user manual, which
you should refer to time and again.
So these data types are
Integers, Single Precision Numbers, Double Precision Numbers
and Complex numbers too.
For most of your operations you dont really have to worry about them,
You will really need to know about them once you start working with
conversions between one another and some functions which may specify
input in a prescribed format.
For integers int8,32,64 there are corresponding unsigned versions available.
Conversions from one format to another:
These data types can be converted from one another just by typecasting.
i.e to convert from
int8 to int64 all you have to do is,
a =int8(10);
b =int64(a);
and thats it, you are done.
While converting from floats to integers, there are several options available.
such are popular ceil, floor, round as well as direct conversion by typecasting. (int64.. etc).
Interesting example I found on matlab manual website was to convert
string to corresponding ascii characters..!
Writing this blog is really useful..!:) I get to know many new functions as well.
Ok,coming back,
str = 'Hello World'; int8(str) ans = 72 101 108 108 111 32 87 111 114 108 100
Heres what happens if you convert string to integers.
Images are typically read in int8 arrays. So while storing them back,
its great if you can convert them back to int8.
While converting though or while working with various integer types,
you have to take care not to exceed max limit of data type you have
selected.
Matlab comes with some warning messages related to these integer types.
You can toggle them with
intwarning('on'); and intwarning('off');These come in very handy if you are much into data conversion,If you are not really bothered about memory, you may want to work with the highest capacity data type possiblePlease have a look at intmax function I know that this blog post was bit a reading material than practical examples.But really going deep inside into every data type is beyond scope of this writing.
Though in matlab you dont have to worry about data types, be extremely careful about them and especially their ranges. The can cause disasters ina great code..!

