Find cells with specific condition

3 visualizzazioni (ultimi 30 giorni)
Ting-Yu Chueh
Ting-Yu Chueh il 24 Ott 2020
Risposto: dpb il 24 Ott 2020
Hi everyone,
As the attachment, there is a cell array. I want to find specific cells as below:
Con1= {11 2}; Con2= {12 1};
Now, I can select above cells as following code.
Con1= {11 2};
Con2= {12 1};
Con1incorrect = find (cellfun(@(x) isequal (x,Con1), condition(1,:)));
Con2incorrect = find (cellfun(@(x) isequal (x,Con2), condition(1,:)));
But, I only want to select those cells that with following specific cells like Correctcon1 = {11 1} or Correctcon2 = {12 2},
How can I do that?

Risposta accettata

dpb
dpb il 24 Ott 2020
First of all, not all elements of condition contain two elements so you'll have to special-case those or fix that anomaly. Use a NaN or something else for missing value indicator would be one way.
If do that, then there's no need for cell array at all; then just use
match=[11 1]; % wanted matching pattern
isMatch=ismember(condition,match,'rows'); % find matching indices in fixed condition array

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by