Sorting a cell of strings using a certain character position
    6 ビュー (過去 30 日間)
  
       古いコメントを表示
    
Dear all
I have a variable called var=
vart=[{'Ice011_L_3of3m.mat''}; {'Ice011_P_1of3m.mat'} ;{'Ice011_P_2of3m.mat'}]
We would need to sort the strings in the cell array using the 10th character of each string, so we would get the following result
var_sorted =[{'Ice011_P_1of3m.mat'}; {'Ice011_P_2of3m.mat'} ;{'Ice011_L_3of3m.mat'}]
Many thanks in advance
paramonte
0 件のコメント
採用された回答
  Stephen23
      
      
 2019 年 2 月 22 日
        
      編集済み: Stephen23
      
      
 2019 年 2 月 22 日
  
      Simpler in two lines:
vart = {'Ice011_L_3of3m.mat';'Ice011_P_1of3m.mat';'Ice011_P_2of3m.mat'}
[~,idx] = sort(cellfun(@(v)v(10),vart));
vart = vart(idx)
If you need to match more than one digit you could use a regular expression, e.g.:
[~,idx,] = sort(str2double(regexp(vart,'(?<=_)\d+','match','once')));
その他の回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

