cellfun is slow for lexical sort

2 views (last 30 days)
Preethi on 3 Oct 2013
Commented: Preethi on 4 Oct 2013
I am trying to lexicogrphically sort a matrix (size - 10000x 1) and i used cellfun, but it is very time consuming. Is there any way to speed up. I tried using for loop but i couldn't get the correct result. My code is
im_dct_num = num2cell(im_dct);
im_dct_temp = cellfun(@num2str,im_dct_num,'UniformOutput',false);
Thanking you in advance
  1 Comment
Walter Roberson
Walter Roberson on 3 Oct 2013
So to check, you would want to sort 1 then 10 to 19 then 2 and so on?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 3 Oct 2013
You should find it faster to use
im_dct_temp = cellstr( num2str( im_dct(:) ) );
but then you need to decide about treating leading or trailing blanks. For example how should
sort relative to
? And would your preferred output for 2 be '2' or '2.' or '2.0' ?
  1 Comment
Preethi on 4 Oct 2013
It is working, speed has improved. If I have to use it for a matrix (ex. 19000 x 64) how do I modify the code?

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!