how to Sorting a cell?

hello all,,
i want to ask u about how to sorting a cell which element is combination number and string
example
f =
[16] 'good'
[25] 'good'
[ 9] 'bad'
[13] 'bad'
i wanna sorting that cell by minimum value
how to make it?

 采纳的回答

[dummy, index] = sort([f{:, 1}]);
sorted_f = f(index, :);

3 个评论

do u know how to choose the 3 first lowest number in that cell after it sorted?
sorted_f(end-2:end, :)
baby
baby 2013-1-21
编辑:baby 2013-1-21
thx u so much :)

请先登录,再进行评论。

更多回答(1 个)

Thorsten
Thorsten 2013-1-21
编辑:Thorsten 2013-1-21
[sorted ind] = sort([f{:, 1}]);
f = f(ind, :)

4 个评论

Thorsten, how to choose the 3 first lowest number in that cell after it sorted?
low3 = [f(end-2:end, 1)];
it just give one result like this
[9]
[13]
[16]
i want the result like this
[9] 'bad'
[13] 'bad'
[16] 'good'
how to make like that?
nLow=3;
[f, ind] = sort([f{:, 1}]);
fLow = f(1:nLow, :)

请先登录,再进行评论。

类别

帮助中心File 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