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 lengthmyVector = myMatrix{1}; % <-- The first element of myMatrix extracted ... a 1x2 row vectoranotherVector = myMatrix{2}; % <-- the 1x3 row vectoretc.Be sure to use the curly braces { } to build the cell array and to extract the vectors. Related SolutionsMATLAB: How to create a matrix from specific Cell array elements Where C is your cell array: cell2mat(C(1:2,1:2)) MATLAB: Element replacement of matrix. If using a for loop is not actually a requirement you can do this very simply as such:myMatrix = rand(5,4); % create 5x4 matrixmyMatrix(3,:) = 1:4; % replace valuesIf the for loop is a requirement:myMatrix = rand(5,4); % create 5x4 matrixfor n = 1:4 myMatrix(3,n) = n;end Related QuestionManipulation of a cell array-Convert an 18×1 cell array in a 3×6 cell arrayMena of each row in matrixSeparating matrix into column vectorsTransform a 3d matrix into cell array
Best Answer