MATLAB: A Matrix full of Arrays

matrixvector

Is there any way to fill a matrix full of arrays? So you would call myMatrix(1,1) and it would return a vector myVector = myMatrix(1,1)
myVector(2) would then return an integer

Best Answer

Use cell arrays. E.g.,
myMatrix = {1:2,1:3,1:4}; % <-- 3-element cell array of row vectors, each a different length
myVector = myMatrix{1}; % <-- The first element of myMatrix extracted ... a 1x2 row vector
anotherVector = myMatrix{2}; % <-- the 1x3 row vector
etc.
Be sure to use the curly braces { } to build the cell array and to extract the vectors.