How do I move certain rows up or down in a cell array?
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a cell array, which is sorted alphabetically. I need to move any row that contains a marker (for example, X), to the top of the list. How do I do that?
e.g.:
AAA AAB FFF FTD JJJ XXX XXY ZAF ZAE
So, I just need to move XXX and XXY to the beginning, and the rest of the array should remain the same.
Does anyone know of a script to do this automatically?
Thanks
0 commentaires
Réponse acceptée
Matt J
le 23 Oct 2012
Modifié(e) : Matt J
le 23 Oct 2012
idx=~cellfun('isempty', strfind(yourcell,'X'));
yourcell=yourcell(:).';
yourcell=[yourcell(idx), yourcell(~idx)];
3 commentaires
Matt J
le 23 Oct 2012
Yes. If your cell array is really vertical and you want to keep it that way, just delete the 2nd line and concatenate vertically in the final line.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!