MATLAB Answers


Assigning each column of a matrix to a cell

Asked by AP
on 11 Jun 2011

I have four 19829x1000 matrices. 1000 is the number of different measurement. I want to assign each column to an array in the following format. According to the following code, I need c{1}{1} to be the value of first variable, A, for the first experiment; that is c{1}{1}=A(:,1) ans so forth. As another example, I want c{3}{456} to be the value of the third variable, C, for the 456th experiment; that is c{3}{456}=C(:,456).

A; % 19829x1000 matrix containing the value of A
B; % 19829x1000 matrix containing the value of B
C; % 19829x1000 matrix containing the value of C
D; % 19829x1000 matrix containing the value of D
c=cell(4, 1000);

Unfortunately, it doesn't work. I also tried DEAL function:


but this one doesn't work either.

Please help me.



No products are associated with this question.

1 Answer

Answer by Matt Fig
on 11 Jun 2011
 Accepted answer

As an example:

A = round(rand(6,3)*20)
B = round(rand(6,3)*-20)
C{1} = mat2cell(A,size(A,1),ones(1,size(A,2)));
C{2} = mat2cell(B,size(B,1),ones(1,size(B,2)));
% Now look at the cell:
C{1}{3}   % Should look like A(:,3)
C{2}{2}   % Should look like B(:,2)


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!