Sorting cell array of strings wrt. a character
Show older comments
Say I have:
SM={'JJ','AKs','TT','AQs','AKo','AJs','KQs','99','ATs','AQo'}
and I would like to sort it wrt. {XXs}, {YYo} and {the remaining strings} (i.e. strings without 's' or 'o'). How can that be done?
Accepted Answer
More Answers (1)
Andrei Bobrov
on 5 Jun 2012
k = cell2mat(cellfun(@(x)find(~cellfun('isempty',regexp(SM,x))),{'s' 'o'},'un',0))
out = SM([k setdiff(1:numel(SM),k)])
Categories
Find more on Characters and Strings 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!