num2str function:
The num2str function, that converts real numbers, can be called in many ways. If only the real number is passed to the num2str function, it will generate a string which has four decimal places, that is the default in MATLAB for showing real numbers. The precision can also be identified (that is the number of digits), and format strings can also be passed, which is as shown below:
>> str2 = num2str(3.456789)
str2 =
3.4568
>> length(str2)
ans =
6
>> str3 = num2str(3.456789,3)
str3 =
3.46
>> str = num2str(3.456789,'%6.2f')
str =
Note that in the last illustration, MATLAB eliminate the leading blanks from the string.