Clear Filters
Clear Filters

how to Sorting a cell?

1 view (last 30 days)
baby
baby on 21 Jan 2013
Commented: dpb on 3 Oct 2021
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?

Accepted Answer

Jan
Jan on 21 Jan 2013
[dummy, index] = sort([f{:, 1}]);
sorted_f = f(index, :);
  3 Comments
Jan
Jan on 21 Jan 2013
sorted_f(end-2:end, :)
baby
baby on 21 Jan 2013
Edited: baby on 21 Jan 2013
thx u so much :)

Sign in to comment.

More Answers (1)

Thorsten
Thorsten on 21 Jan 2013
Edited: Thorsten on 21 Jan 2013
[sorted ind] = sort([f{:, 1}]);
f = f(ind, :)
  4 Comments
baby
baby on 21 Jan 2013
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?
dpb
dpb on 3 Oct 2021
nLow=3;
[f, ind] = sort([f{:, 1}]);
fLow = f(1:nLow, :)

Sign in to comment.

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!