Assigning each column of a matrix to a cell

4 ビュー (過去 30 日間)
AP
AP 2011 年 6 月 11 日
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.

採用された回答

Matt Fig
Matt Fig 2011 年 6 月 11 日
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 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by