Find a certain cell in a cell array?

2 vues (au cours des 30 derniers jours)
Pooya Ferdosipour
Pooya Ferdosipour le 23 Août 2015
Hello all,
Suppose we have a a cell array 3x3 there is one matrices in each cell. we already know that if A=[1 0 3 49 5 6 7] then A(4)=49 and also we can easily find the location of 49 in matrices by using find(A==49). But it does not work for cell array! for example if I assume a cell array : I= {[1,2] [2,3] [4,5] ; [6,6] [0.8,8] [2,3] ; [1.1,4] [1,1] [2,2] }
I can not say find I ==[0.8,8] and the answer gives me "5" (the 5th cell). How can I find the locations for a certain value of cell like [0.8,8]?
All the best,

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 23 Août 2015
I={ [1,2] [2,3] [4,5] ;
[6,6] [0.8,8] [2,3] ;
[1.1,4] [1,1] [2,2] }
[ii,jj]=find(cellfun(@(x) isequal(x,[0.8,8]),I))
  1 commentaire
Pooya Ferdosipour
Pooya Ferdosipour le 24 Août 2015
Modifié(e) : Pooya Ferdosipour le 24 Août 2015
thanks alot :) (LIKE)

Connectez-vous pour commenter.

Plus de réponses (1)

Walter Roberson
Walter Roberson le 23 Août 2015
find(cellfun(@(C) isequal(C, [0.8,8]), I)
However, floating point numbers are seldom equal even when they look like they are. 0.8 cannot be represented exactly in binary floating point (just like 1/3 cannot be represented exactly as a finite decimal), and the exact value stored is going to depend on the exact way that the value was calculated.
  1 commentaire
Pooya Ferdosipour
Pooya Ferdosipour le 24 Août 2015
Modifié(e) : Pooya Ferdosipour le 24 Août 2015
thanks alot :) I get what I wanted.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Matrices and Arrays 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