Find an vector in a cell array

2 vues (au cours des 30 derniers jours)
Zhangxi Feng
Zhangxi Feng le 15 Juin 2017
Commenté : Fangjun Jiang le 16 Juin 2017
I have a cell array of up to hundreds of elements say A = cell(1,100). Each cell has a variety of three-column vectors (all 3-columns but could vary in number of rows): A{1} = [1 2 3; 4 5 6; 7 8 9]; etc.
Is there a way to use the built-in functions to see if the vector [1 2 3] exist in A?

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 15 Juin 2017
A{1}= [1 2 3; 4 5 6; 7 8 9];
A{2}= [11 2 3; 4 5 6];
A{3}= [1 12 3];
IsInA=any(cellfun(@(x) ismember([1 2 3], x,'rows'),A))
  2 commentaires
Zhangxi Feng
Zhangxi Feng le 15 Juin 2017
Thanks! I have used similar clauses before but never really understood how it works. What is the meaning of @(x)?
Fangjun Jiang
Fangjun Jiang le 16 Juin 2017
doc('anonymous functions')

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by