Assigning each column of a matrix to a cell
5 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!