Find cells with specific condition

4 Ansichten (letzte 30 Tage)
Ting-Yu Chueh
Ting-Yu Chueh am 24 Okt. 2020
Beantwortet: dpb am 24 Okt. 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?

Akzeptierte Antwort

dpb
dpb am 24 Okt. 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

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by