MATLAB: Matrix whose cell arrays are vectors

MATLABmatrix arraymatrix manipulation

Hi,
I am trying to form a 5×20 matrix whose arrays are themselves 3×1 matrix (x(i), y(i), z(i)) in each row:
x = zeros(1, 20);
y = -47.5 : 5: -32.5;
z = (22.5 :-5: 12.5)';
z is a 5×1 matrix which is the same in each column.
How do I do that?
Thank you!

Best Answer

I am going to try to take my best guess at what you mean. At the very least, you will see one way to structure this.
% Your example contents
x = zeros(1, 20);
y = -47.5 : 5: -32.5;
z = (22.5 :-5: 12.5)';
% Define the highest-level cell array
M = cell(5,20);
% Define that the first cell of M contains a 1x3 cell array
M{1,1} = cell(1,3);
% Fill each of the three cells with its contents
M{1,1}{1} = x;
M{1,1}{2} = y;
M{1,1}{3} = z;
This is all probably a terrible way of organizing whatever data you have.