How do I reduce an {nxm(3x1)} cell to a an {nx{3xm}} cell?

I apologize in advance if this seems trivial.
I have an {nxm(3x1)} object. That is, I have an n x m cells, each a 1x3 matrice. I'd like to reduce this so that I have {nx1} cells, each of which contain 1 {3xm} cell (or double, it doesn't matter) so that I can easily export the various 3xm matrices to n different 3xm arrays within an excel spreadsheet.
I've made various attempts at writing for loops, to no avail.
Any insight would be greatly appreciated.
Thanks.
EDIT: apparently I didn't look close enough at the cells, they are actually 1x3 doubles vice the original 3x1 I had stated.

 채택된 답변

Iman Ansari
Iman Ansari 2013년 4월 16일
Hi
New_Cell={};
for i=1:n
New_Cell{i,1}=cell2mat(C(i,:));
end

댓글 수: 1

Thanks for the help. That gets me closer, but every n in New_Cell is now 1x(3*m) instead of 3xm.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Zach Modig
Zach Modig 2013년 4월 16일
편집: Zach Modig 2013년 4월 16일
Once I accounted for the actual structure of the cells, Iman's answer proved to be the correct one. I had to invert each cell into a 3x1 structure, and then the loop using cell2mat that Iman correctly suggested.
for j = 1:n
for k = 1:m
C{j,k} = C{j,k}';
New_Cell{j,1} = cell2mat(C(j,:));
end
end

댓글 수: 1

Try this:
C=cellfun(@transpose,C,'UniformOutput', false)
New_Cell={};
for i=1:n
New_Cell{i,1}=cell2mat(C(i,:));
end
New_Cell

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Type Conversion에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by