Page 370 - Process Modelling and Simulation With Finite Element Methods
P. 370

A MATLAB/FEMLAB Primer for Vector Calculus    351

          >>a= [1234; 56781;
          >>  size(a)
          ans =
               2    4
          Size of an array is itself a row vector of length equal to the array dimensions.
          >>  length (a (1, ) )
                       :
          ans =
               4
          The colon (:) placeholder  in the second argument of a specifies the entire range
          of the second dimension, in this case elements  1 :4, i.e.  1 thru 4.
          >>  length(a(:,3))
          ans =
               2
          >>  a(1,2:4)
          ans =
               2    3     4
          In fact, the colon refers to subarrays of a lower dimension. a( 1,:) is the first row;
          a(:,3) is the third column of a.  a(1, 2:4) gives a subarray of elements 2 thru 4 of
          row  1.  In higher dimensions, the subarrays extracted are more complicated.  For
          instance








          >>  b(1, :)
          ans =
               1    1     1     1
          Here, the subarrays are matrices in the first two cases, but in the third case, the
          final two dimensions are rolled up into a single row vector.

          FORTRAN programmers  will probably feel more comfortable addressing  single
          elements





          rather than subarrays, perhaps by using looping structures.

          Array Construction
          Arrays can be automatically generated using colon notation, viz.
   365   366   367   368   369   370   371   372   373   374   375