how to sort the rows in an cell array.

1 view (last 30 days)
I am having cell array of size 3x1
could anyone help me how to sort the rows to get the result in the following manner
  1 Comment
Scott MacKenzie
Scott MacKenzie on 24 Jun 2021
It would help if you posted the code that generates the cell array you want to sort.

Sign in to comment.

Accepted Answer

Mohammad Sami
Mohammad Sami on 25 Jun 2021
You can try this out.
B = {[5,6] [1,2] [5,8]};
[~,i] = sort(cellfun(@(x)sum(x.*power(10,[length(x):-1:1]-1)),B));
B = B(i)
B = 1×3 cell array
{[1 2]} {[5 6]} {[5 8]}
jaah navi
jaah navi on 25 Jun 2021
Thanks for your explanation.

Sign in to comment.

More Answers (0)


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


Community Treasure Hunt

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

Start Hunting!