collapsing rows of a cell array into a single cell

조회 수: 16 (최근 30일)
Billy
Billy 2023년 1월 31일
댓글: Billy 2023년 1월 31일
I have a 312x3 cell called 'data'. In the first column there are 312 rows of different x-values, the second column there are 312 rows of different y-values, and in the third column there are 312 rows of t-values. I want to collapse all the rows of each column into a single cell, such that all the x-values are in a single cell (first column), all the y-values are in a single cell (second column), and all the t-values are in a single cell (third column). For instance, if I started with the following 6x4 cell array called Data:
Data =
0.935 4 24 0.07
0.759 5 74 0.01
0.681 2 21 0.09
0.823 1 16 0.06
0.894 3 7 0.01
0.953 5 67 0.03
I can't figure out how to transform this into the following 1x4 cell array (Data2)
Data2 =
([0.935 0.759 0.681 0.823 0.894 0.953] [4 5 2 1 3 5] [24 74 21 16 7 67] [0.07 0.01 0.09 0.06 0.01 0.03], :)
Is there a piece of code that can do this?
I hope this makes sense! Thanks for the help.
Best wishes,
Billy

채택된 답변

Matt J
Matt J 2023년 1월 31일
편집: Matt J 2023년 1월 31일
Data2=num2cell(Data,1);
However, I wonder why you would want to do this. Matrices are usually faster to manipulate than cells, and you can do matrix math with them.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by