Page 45 - Applied Statistics Using SPSS, STATISTICA, MATLAB and R
P. 45

24       1 Introduction


              >> c(1,2)={‘T80’};
              >> c(1,3)={‘T82’};
              >> c
              c =
                  ‘Pmax’    ‘T80’    ‘T82’

              The first command uses function cell   to define a cell array with 1×3 objects.
           These are afterwards assigned some  string values (delimited  with  ‘). When
           printing the c  values one gets the confirmation that c  is a row vector with the three
           strings (e.g., c(1,2) is ‘T80’).
              When specifying matrices in MATLAB one may use comma to separate column
           values and semicolon to separate row values as in:

              » x=[1, 2 ; 3, 4];

              Matrices can also be used to define other matrices. Thus, the previous matrix x
           could also be defined as:

              » x=[[1 2] ; [3 4]];
              » x=[[1; 3], [2; 4]];

              One can confirm that the matrix has been defined as intended, by typing x  after
           the prompt, and obtaining:

              x =
                   1     2
                   3     4
              The same result could be obtained by removing the semicolon terminating the
           previous command.  In MATLAB a semicolon inhibits  the production of screen
           output. Also MATLAB commands can either be used in a procedure-like manner,
           producing output (as “answers”, denoted  ans), or in a function-like  manner
           producing a value assigned  to a variable (considered to be a  matrix). This is
           illustrated next, with the command that computes the mean of a sequence of values
           structured as a row vector:

              » v=[1 2 3 4 5 6];
              » mean(v)
              ans =
                  3.5000
              » y=mean(v)
              y =
                  3.5000

              Whenever needed one may know which objects (e.g. matrices) are currently in
           the console environment by issuing who  . Object removal is performed by writing
           clear   followed by the name of the object. For instance,  clear x   removes
           matrix x  from the environment; it will no longer be available. The use of clea r
           without arguments removes all objects from the environment.
   40   41   42   43   44   45   46   47   48   49   50