필터 지우기
필터 지우기

How to find the position of a number in an cell-array?

조회 수: 6 (최근 30일)
Nazmun Nahar Khan
Nazmun Nahar Khan 2021년 2월 26일
댓글: Nazmun Nahar Khan 2021년 2월 26일
I have a cell array P= {[2,5], [3], [], [1,14], [], [9]}. I want to find out the number of cell where value 14 is located. Like, here 14 is located inside the cell number 4.
How can I do that?
  댓글 수: 2
tzela yaish
tzela yaish 2021년 2월 26일
how do i create my own question ?
Nazmun Nahar Khan
Nazmun Nahar Khan 2021년 2월 26일
Hi yaish, you need to go 'ask' in the top.

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

채택된 답변

KSSV
KSSV 2021년 2월 26일
편집: KSSV 2021년 2월 26일
P= {[2,5], [3], [], [1,14], [], [9]} ;
N = length(P) ;
val = 14 ;
for i = 1:N
idx = ismember(14,P{i}) ;
if any(idx)
break
end
end
i
P{i}
  댓글 수: 5
KSSV
KSSV 2021년 2월 26일
편집: KSSV 2021년 2월 26일
cellfun uses loop behind. find will be slow.

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

추가 답변 (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