Find cells with specific condition

1 回表示 (過去 30 日間)
Ting-Yu Chueh
Ting-Yu Chueh 2020 年 10 月 24 日
回答済み: dpb 2020 年 10 月 24 日
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?

採用された回答

dpb
dpb 2020 年 10 月 24 日
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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by