I have the following cell structure:
1x30 double
1x23 double
1x23 double
1x23 double
1x23 double
1x23 double
1x23 double
1x25 double
1x35 double
I want to find whether a number is present in one of these and want to know the index of that. So for instance the number 5 is present in double 1, 5 and 7, so the output should be [1 5 7]. Can this be done?

댓글 수: 4

Alex Mcaulley
Alex Mcaulley 2019년 8월 7일
Take a look to cellfun
madhan ravi
madhan ravi 2019년 8월 7일
Unclear, attach your data as .mat file.
KSSV
KSSV 2019년 8월 7일
Read about ismember, find.
Adam
Adam 2019년 8월 7일
편집: Adam 2019년 8월 7일
Off the top of my head, something like this may work:
find( cellfun( @(x) any( find( x == 5 ) ), myCell, 'UniformOutput', false ) )
where myCell is your cell array.
At least it may give you ideas to get to the right solution, though I'm sure someone else will quickly come along with a correct or better solution if this is not it!

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

 채택된 답변

madhan ravi
madhan ravi 2019년 8월 7일
편집: madhan ravi 2019년 8월 7일

0 개 추천

v=cellfun(@(x) any( x == 5 ), yourcell);
Wanted = find(v) % Adam was almost right , but a minute tweak

댓글 수: 3

Stephen23
Stephen23 2019년 8월 7일
편집: Stephen23 2019년 8월 7일
Simpler:
find(cellfun(@(x)any(x(:)==5),yourcell))
That any(find(...)) syntax is rather obfuscated, and should be avoided.
madhan ravi
madhan ravi 2019년 8월 7일
Thank you Stephen!
JamJan
JamJan 2019년 8월 7일
Thank you guys!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

질문:

2019년 8월 7일

댓글:

2019년 8월 7일

Community Treasure Hunt

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

Start Hunting!

Translated by