change a cell having 3-dimenisional matrix into a 2-dimenisional matrix

1 次查看(过去 30 天)
Hi all,
I have a variable named "z" which has the 2-dimensional cell structure like following program:
for tt=1:3
for nn=1:4
z{tt,nn}=rand(2,3,4);
end
end
z =
[2x3x4 double] [2x3x4 double] [2x3x4 double] [2x3x4 double]
[2x3x4 double] [2x3x4 double] [2x3x4 double] [2x3x4 double]
[2x3x4 double] [2x3x4 double] [2x3x4 double] [2x3x4 double];
assume the value of z at tt=1 and nn=1 , i.e. z{1,1}, is qual below: z{1,1}
val(:,:,1) =
0.8147 0.1270 0.6324
0.9058 0.9134 0.0975
val(:,:,2) =
0.2785 0.9575 0.1576
0.5469 0.9649 0.9706
val(:,:,3) =
0.9572 0.8003 0.4218
0.4854 0.1419 0.9157
val(:,:,4) =
0.7922 0.6557 0.8491
0.9595 0.0357 0.9340
z{2,1} =
val(:,:,1) =
0.6880 0.5716 0.8095
0.2968 0.3162 0.3655
val(:,:,2) =
0.6988 0.9646 0.5982
0.6334 0.2008 0.0837
val(:,:,3) =
0.5444 0.0407 0.7093
0.8461 0.3294 0.8603
val(:,:,4) =
0.5009 0.4286 0.4730
0.9948 0.2673 0.1608
z{3,1} =
val(:,:,1) =
0.1589 0.7571 0.9669
0.2683 0.6092 0.7733
val(:,:,2) =
0.5729 0.2871 0.0944
0.4502 0.7524 0.1068
val(:,:,3) =
0.7349 0.5806 0.7137
0.3546 0.2989 0.3605
val(:,:,4) =
0.7185 0.0837 0.0938
0.9953 0.4682 0.7252
and so on.
I want to put all elements of z into a matrix and make a new matrix named "zz" whose size is 24*9. for example the zz(:, 1:3) is like below:
zz(:,1:3)=[0.8147 0.1270 0.6324;
0.9058 0.9134 0.0975;
0.2785 0.9575 0.1576;
0.5469 0.9649 0.9706;
0.9572 0.8003 0.4218;
0.4854 0.1419 0.9157;
0.7922 0.6557 0.8491;
0.9595 0.0357 0.9340;
0.6880 0.5716 0.8095;
0.2968 0.3162 0.3655;
0.6988 0.9646 0.5982;
0.6334 0.2008 0.0837;
0.5444 0.0407 0.7093;
0.8461 0.3294 0.8603;
0.5009 0.4286 0.4730;
0.9948 0.2673 0.1608;
0.1589 0.7571 0.9669;
0.2683 0.6092 0.7733;
0.5729 0.2871 0.0944;
0.4502 0.7524 0.1068;
0.7349 0.5806 0.7137;
0.3546 0.2989 0.3605;
0.7185 0.0837 0.0938;
0.9953 0.4682 0.7252;]
How can I do it? following is any help whould be appreciated. Thanks in advance.

回答(1 个)

Matt J
Matt J 2013-10-11
zz=reshape( cat(2,z{:}) ,[],9);
  3 个评论
Matt J
Matt J 2013-10-13
I think you need to redo the description of what you want. There are 288 doubles total contained across z, yet you claim to want a final matrix zz that is 24x9, which would contain only 216 elements. We also cannot see what data order you want when you only show the first 3 columns of zz.
som
som 2013-10-13
ok, thanks for your response. I have explained my question more clearly through a new question. you can see it soon. I would be thankful if you take a look at that question and give me your feedback.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by