collapsing rows of a cell array into a single cell

8 vues (au cours des 30 derniers jours)
Billy
Billy le 31 Jan 2023
Commenté : Billy le 31 Jan 2023
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

Réponse acceptée

Matt J
Matt J le 31 Jan 2023
Modifié(e) : Matt J le 31 Jan 2023
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.

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by