find if one number is member of a column ,of cell array, that contains cell entries and if it is member, in which row, it appears
    4 ビュー (過去 30 日間)
  
       古いコメントを表示
    
    Ioannis Vourvachakis
 2021 年 11 月 14 日
  
    
    
    
    
    コメント済み: Ioannis Vourvachakis
 2021 年 11 月 14 日
            I have a 23*6 cell array that is called cofPairs.

As you see, the 5th and 6th column contain cell entries, that contain numbers. For example, the first element of the 5th column ( cofPairs{1,5} )

So, what I want to do.
I want to check for several random numbers if they appear in any entry in the 5th column of the array. I want also to know in which rows of the 5th column appear (in any entry).
How can I achieve this?
Thank you!
1 件のコメント
  Jan
      
      
 2021 年 11 月 14 日
				It would be more efficient to store the numbers inb a numerical vector instead of a column cell, which contains scalars.
採用された回答
  Jan
      
      
 2021 年 11 月 14 日
        
      編集済み: Jan
      
      
 2021 年 11 月 14 日
  
      Simplify the data representation at first:
for k = 1:size(C, 1)
   C{k, 5} = [C{k, 5}{:}];
end
Then the searching is easy:
x = 17;
found = false(size(C, 1), 1);
for k = 1:size(C, 1)
   found = any(C{k, 5} == x);
end
Now use found of find(found) as you want.
If you have a good reason to let the elements of the 5.th row be a cell (e.g. if the elements are vectors of different sizes in opposite of the shown example, in which they are scalars):
x = 17;
found = false(size(C, 1), 1);
for k = 1:size(C, 1)
   found = any([C{k, 5}{:}] == x);
end
その他の回答 (0 件)
参考
カテゴリ
				Help Center および File Exchange で Operators and Elementary Operations についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

