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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by