MATLAB: Sorting a matrix alphabetic

matrixthe sorting hat

Hey Guys
I just need a little help/guidance. If i have a matrix [N M] and i need to sort it alphabetically from A->Å What in-built function do i need to use? the matrix is mixed with numbers and text, and it has a headline which should not get affected by the sorting. Thank you in advance! sincerely
– David

Best Answer

If everything is in character form
[tf, idx] = ismember(YourArray, 'AaBbCcDdEeÉéÈèFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZzÅå')
if ~all(tf)
error('bad characters "%s"\n', YourArray(tf));
end
Now you can sort according to the values in idx
Related Question