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

2 vues (au cours des 30 derniers jours)
Nazmun Nahar Khan
Nazmun Nahar Khan le 26 Fév 2021
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 commentaires
tzela yaish
tzela yaish le 26 Fév 2021
how do i create my own question ?
Nazmun Nahar Khan
Nazmun Nahar Khan le 26 Fév 2021
Hi yaish, you need to go 'ask' in the top.

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 26 Fév 2021
Modifié(e) : KSSV le 26 Fév 2021
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 commentaires
KSSV
KSSV le 26 Fév 2021
Modifié(e) : KSSV le 26 Fév 2021
cellfun uses loop behind. find will be slow.
Nazmun Nahar Khan
Nazmun Nahar Khan le 26 Fév 2021
Thanks

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by