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

4 次查看(过去 30 天)
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?

采纳的回答

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 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by