Arrays in Matlab

Arrays in Matlab follow the standard rules of arrays. Arrays are numbered lists of related data. Matlab has a number of builtin commands and functions for use with arrays, including length, and the colon notation.

Arrays in Matlab

The : (Colon Notation)

The colon notation produces an array of values, starting with the first value, incrementing (counting) by the second number (which if not present, has a default of 1), and ending when the count passes the final value.

        
  1:1:10   % produces the array [1 2 3 4 5 6 7 8 9 10] 
  1:10     % also produces the array [1 2 3 4 5 6 7 8 9 10] 
  1:2:10   % produces the array [1 3 5 7 9] 
  1:.5:2   % produces the array [1.0 1.5 2.0]


  times = .5:.5:10;  % produce an array of "times" starting at half a
                     % second, increasing by half a second, and ending at 10 seconds
        
      

Back to Topics List