Page 838 - Mechatronics with Experiments
P. 838

824   MECHATRONICS

                              >> save filename     var1   var2    -ascii   -double -tab
                                  %   saves the selected variables in ascii format in the
                                      filename specified.
                                  %   if no variable name is provided, all of the variables
                                  %   in workspace is saved.

                                   Data can be displayed in text format on the screen, plotted in graphical form, or saved
                              toafile,
                                  x
                                      %  Not terminating a line in m-file (or in command
                                         window) ";" displays
                                      %  the numerical result of the current line on the
                                         screen including the name of the variables
                                    disp(x)
                                      % Displays the value of x without printing the name of
                                        the variable

                                    disp(’Message’);
                                      %    display the text string ’Message’

                                   Formatted printing to screen or file can be done using the fprintf() function, which
                              is almost identical to the fprintf() function used in C language.

                              A = [1    2  3 ;
                                     4   5  6  ]  ;
                               [row,col]=size(A) ;


                               fprintf(’The matrix has %4.0f rows and \t %4.0f columns \r\n’,
                               row, col) ;

                                 %    the ’%5d’      means the data for 5 digit integer format,
                                 %    the ’%4.0f’    means the data is in decimal    notation,
                                 %                   4 characters long, 0 digits after the decimal
                                                     point.

                                myTitle = ’Result: Force versus Time’ ;
                                fprintf(’%s \n’, myTitle) ;

                                   The result is

                              >>
                              The matrix has       2 rows and        3 columns

                              Result: Force versus Time
                              >>

                              The

                              \n
                              format specifier adds a carriage-return after printing “myTitle” on the screen. In the above
                              example, “fprintf()” statements print on the screen.
   833   834   835   836   837   838   839   840   841   842   843