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

Learn moreOpportunities for recent engineering grads.

Apply Today
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); [c{1,:}]=mat2cell(A); [c{2,:}]=mat2cell(B); [c{3,:}]=mat2cell(C); [c{4,:}]=mat2cell(D);

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

[c{1,:}]=deal(mat2cell(A));

but this one doesn't work either.

Please help me.

*No products are associated with this question.*

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)

## 0 Comments