Sort cell array with numeric data by values of first index in matrix

조회 수: 1 (최근 30일)
dm
dm 2011년 10월 25일
Hello,
I got a set of contour data obtained by [C h] = contour(X,Y,Z) which I want to split into a cell array and sort with respect to contour level.
E.g. C might look like (a lot more than 1 point per level in the real data, but just to illustrate):
80.7815 1.0000
-0.7920 0.1039
32.1231 1.0000
0.9921 0.4542
72.1341 1.0000
-0.1358 0.4279
Then I want the cell array to look like:
Cn{1} = [32.1231 1; 0.9921 0.4542];
Cn{2} = [72.1341 1; -0.1358 0.427];
Cn{3} = [80.7815 1; -0.7920 0.1039];
however, what I manage to produce myself is:
Cn{1} = [80.7815 1; -0.7920 0.1039];
Cn{2} = [32.1231 1; 0.9921 0.4542];
Cn{3} = [72.1341 1; -0.1358 0.427];
So the question is, how can I sort the cells after Cn{k}(1,1)?
Best regards, dm

채택된 답변

dm
dm 2011년 10월 25일
Managed to figure it out:
firstIdx = cellfun(@(x)x(1,1),Cn);
[dummy,order] = sort(firstIdx);
Cns = Cn(order);

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by