Convert cell array to matrix with two columns and sort rows by first column value
3 次查看(过去 30 天)
显示 更早的评论
Hello,
I have a large Cell array with multiple cells. Every these cells has n-rows and two columns.
I want to convert this cell-array to one large matrix with j x 2 double matrix (j is sum value of all rows of all cells)
Cell_x =
1×8 cell array
Columns 1 through 4
{13×2 double} {10×2 double} {9×2 double} {11×2 double}
Columns 5 through 8
{9×2 double} {12×2 double} {6×2 double} {7×2 double}
Matrix_x =
77 x 2 double
after it, I want to sort the rows by values of the first column:
Test_unsorted =
4 45
8 78
9 77
1 68
Test_sorted =
1 68
4 45
8 78
9 77
Thank you for your help!
0 个评论
采纳的回答
更多回答(1 个)
the cyclist
2021-2-10
编辑:the cyclist
2021-2-10
I think this does what you want:
% Set RNG seed, for repeatability
rng default
% Make up some data
Cell_x = {rand(13,2),rand(7,2)};
% Convert cell to matrix, and sort rows by first column
sortrows(cell2mat(Cell_x'),1)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!