This task is about arrays.

For hashes or associative arrays, please see Creating an Associative Array.

For a definition and in-depth discussion of what an array is, see Array.



Task

Show basic array syntax in your language.

Basically, create an array, assign a value to it, and retrieve an element   (if available, show both fixed-length arrays and
dynamic arrays, pushing a value into it).

Please discuss at Village Pump:   Arrays.

Please merge code in from these obsolete tasks:

   Creating an Array
   Assigning Values to an Array
   Retrieving an Element of an Array


Related tasks

   Collections
   Creating an Associative Array
   Two-dimensional array (runtime)


>> a = [1 2 35] %Declaring a vector (i.e. one-dimensional array)
 
a =
 
     1     2    35
 
>> a = [1 2 35;5 7 9] % Declaring a matrix (i.e. two-dimensional array)
 
a =
 
     1     2    35
     5     7     9
 
>> a3 = reshape(1:2*3*4,[2,3,4]);   % declaring a three-dimensional array of size 2x3x4
 
a3 =
 
ans(:,:,1) =
 
   1   3   5
   2   4   6
 
ans(:,:,2) =
 
    7    9   11
    8   10   12
 
ans(:,:,3) =
 
   13   15   17
   14   16   18
 
ans(:,:,4) =
 
   19   21   23
   20   22   24
 
 
>> a(2,3) %Retrieving value using row and column indicies
 
     9
 
>> a(6) %Retrieving value using array subscript
 
ans =
 
     9
 
>> a = [a [10;42]] %Added a column vector to the array
 
a =
 
     1     2    35    10
     5     7     9    42
 
>> a(:,1) = [] %Deleting array elements
 
a =
 
     2    35    10
     7     9    42