How to find index of the following problem?

조회 수: 1 (최근 30일)
SM
SM 2019년 10월 29일
답변: SM 2019년 10월 29일
A={[];13;[1,5];10;7;[];8;3;5;18;[];[1,4];[2,33];[3,17];[4,37];[5,1];[6,28];[7,20];[8,15]};
B={[1 10 5]};
Output=[3;4;9]
the elements of index 3 , 4 and 9 in A are contained by B and therefore the output is [3;4;9].
What is the easiest way of getting this output?

채택된 답변

Walter Roberson
Walter Roberson 2019년 10월 29일
find( cellfun(@(v) all(ismember(v, B)), A))
  댓글 수: 2
SM
SM 2019년 10월 29일
That's excellent! One problem is that It also considers the empty cell. Is it possible to exclude [] ? Because it results [1; 3; 4; 6; 9; 11; 16] instead of [3;4;9].
Walter Roberson
Walter Roberson 2019년 10월 29일
find( cellfun(@(v) ~isempty(v) && all(ismember(v, B)), A))

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

SM
SM 2019년 10월 29일
Thank you! It works now.

카테고리

Help CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by