Is it possible to form a matrix with strings and manipulate them?
    5 ビュー (過去 30 日間)
  
       古いコメントを表示
    
    Harrison Kurunathan
 2017 年 1 月 20 日
  
    
    
    
    
    回答済み: Jorge Mario Guerra González
      
 2017 年 1 月 20 日
            Can I make a matrix like [(a,b), (c,d), (d,f) ; (t,a), (a,b), (g, a); (a,f),(c,d),(a,g) ] and then reorder the rows based on the maximum number of same strings (say a ) in the matrix? the answer will be [(t,a), (a,b), (g, a); (a,f),(c,d),(a,g) ; (a,b), (c,d), (d,f)]
2 件のコメント
  James Tursa
      
      
 2017 年 1 月 20 日
				Please give an explicit example so we know for sure the data types you are working with and how they are stored in variables.
  John Chilleri
      
 2017 年 1 月 20 日
				One method to store a matrix of strings is with cell. Otherwise, I second James, an explicit example would be useful!
採用された回答
  Jorge Mario Guerra González
      
 2017 年 1 月 20 日
        Try this, it's using cell arrays. However I believe that in the newest versions of matlab cell arrys that include Sting work in a different way.
 m={['a','b'], ['c','d'], ['d','f'] ; ['t','a'], ['a','b'], ['g', 'a']; ['a','f'],['c','d'],['a','g']}
counter=zeros(size(m,1),1);
for i=1:size(m,1)
    for j=1:size(m,2)
    counter(i)=counter(i)+length(strfind(m{i,j},'a'));
    end
end
[~,ind]=sort(counter,'descend');
result=m(ind,:)
hope it helps
0 件のコメント
その他の回答 (1 件)
  Walter Roberson
      
      
 2017 年 1 月 20 日
        Matrices of strings require R2016b or later. Before that you need cell arrays of character vectors.
0 件のコメント
参考
カテゴリ
				Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



