Page 13 - Applied Numerical Methods Using MATLAB
P. 13

2    MATLAB USAGE AND COMPUTATIONAL ERRORS
           want to be done. The help command helps you know the usage of a particular
           command/function. You may type directly in the Command window
            >>lookfor repeat   or   >>help for

           to find the MATLAB commands in connection with ‘repeat’ or to obtain infor-
           mation about the “for loop”.

           1.1.1  Input/Output of Data from MATLAB Command Window
           MATLAB remembers all input data in a session (anything entered through direct
           keyboard input or running a script file) until the command ‘clear()’is given or
           you exit MATLAB.
              One of the many features of MATLAB is that it enables us to deal with the
           vectors/matrices in the same way as scalars. For instance, to input the matri-
           ces/vectors,
                                             
                                            3
                       12    3
                 A =            ,    B =    −2   ,  C = 1 −23 −4
                       45    6
                                            1
           type in the MATLAB Command window as below:
           >>A=[123;456]
             A = 1   2    3
                 4   5    6
           >>B = [3;-2;1]; %put the semicolon at the end of the statement to suppress
                           the result printout onto the screen
           >>C=[1-2    3 -4]

           At the end of the statement, press <Enter> if you want to check the result
           of executing the statement immediately. Otherwise, type a semicolon “;” before
           pressing <Enter> so that your window will not be overloaded by a long display
           of results.

           1.1.2  Input/Output of Data Through Files
           MATLAB can handle two types of data files. One is the binary format mat-
           files named ***.mat. This kind of file can preserve the values of more than one
           variable, but will be handled only in the MATLAB environment and cannot be
           shared with other programming environments. The other is the ASCII dat-files
           named ***.dat, which can be shared with other programming environments, but
           preserve the values of only one variable.
              Below are a few sample statements for storing some data into a mat-file in
           the current directory and reading the data back from the mat-file:

            >>save ABCABC %store the values of A,B,C into the file ’ABC.mat’
            >>clear A C %clear the memory of MATLAB about A,C
   8   9   10   11   12   13   14   15   16   17   18