How do I move certain rows up or down in a cell array?
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Matt J
2012-10-23
编辑:Matt J
2012-10-23
idx=~cellfun('isempty', strfind(yourcell,'X'));
yourcell=yourcell(:).';
yourcell=[yourcell(idx), yourcell(~idx)];
3 个评论
Matt J
2012-10-23
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrices and Arrays 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!