Page 825 - Mechatronics with Experiments
P. 825

®
                                                               ®
                                                 MATLAB , SIMULINK , STATEFLOW, AND AUTO-CODE GENERATION  811
                             Angle_Matrix =

                                        0          0
                                 90.0000      1.5708
                                180.0000      3.1416
                                270.0000      4.7124
                                360.0000      6.2832
                             >>


                             The default numerical data type in MATLAB ®  is double precision floating point data,
                             double in C-language. Data can be defined and converted to integer data type using data
                             conversion functions. MATLAB ®  supports 8-bit, 16-bit, 32-bit, and 64-bit signed and
                             unsigned integer data types. The data conversion function examples are shown below,

                                  k1=int8(-10.3)
                                  l1=int16(-1000.4)
                                  m2=uint32(1000000.5)
                                  n2=uint64(-100000000.6)

                             >>
                             k1 =    -10
                             l1 =    -1000
                             m2 =     1000001
                             n2 =     0

                             >>

                             Characters and strings (array of characters) are stored as vectors of ASCII code for each
                             character using a single quote to assign to a string variable. For instance

                                myTitle=’Plot of Torque versus Speed’ ;
                                size(myTitle)

                             >>
                             ans =
                                   1     27


                             The character array variable (equivalently called the string variable) “myTitle” is a vector,
                             where each element of the vector stores the ASCII code of the characters. The “size()”
                             function counts the number of elements in this variable. The conversion between character
                             representation in ASCII code and numerical representations can be performed as follows,

                                   char(97)       % Prints the character corresponding to
                                                    ASCII code 97:     a
                                   double(’a’)    % ...........ASCII code corresponding to
                                                    character ’a’

                                   S = [’1 2’
                                         ’3 4’] ;
                                   X = str2num(S)

                                   S = num2str(X) ;
   820   821   822   823   824   825   826   827   828   829   830