|
"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <je90bc$ri9$1@newscl01ah.mathworks.com>...
> s = {'z19';
> 'j13';
> 'g13';
> 'z12';
> 'n12';
> 'k12';
> 'z13';
> 'v12';
> 'm12';
> 'j12';
> 'z17';
> 'z15';
> 'x12';
> 'f13';
> 'g12';
> 'h12';
> 'z14';
> 'u12';
> 'm13';
> 'z16';
> 'm15';
> 'q12'}
>
> % If your data contains fix format of one letter and 2 numbers
>
> sort(s)
>
> % If not adapt this:
> letters = cellfun(@(s) s(1), s);
> numbers = cellfun(@(s) sscanf(s(2:end), '%d'), s);
> [~, is1] = sort(numbers);
> [~, is2] = sort(letters(is1));
> s(is1(is2))
>
> % Bruno
Thank you very much Bruno. It works. I actually wanted to sort at first numbers and after that letters according to rule above, but it is easy to change your code:
.....
[~, is1] = sort(letters);
[~, is2] = sort(numbers(is1));
....
Thanks!
Boris.
|