problem with making a very simple matrix

3 vues (au cours des 30 derniers jours)
Maryam Vaziri Pashkam
Maryam Vaziri Pashkam le 1 Sep 2011
Hi I am using 32 bit Matlab 2009b on a macintosh computer with OS 10.6.8. I am running in to a problem in Matlab that I cant figure out the reason. Here is my very simple code: c(:,1)=0.30:0.05:0.95; c(:,2)=0.35:0.05:1.00; find(c(:,2)==0.4)
and here is the answer in the command line: ans =
Empty matrix: 0-by-1
supposedly the c(2,2) should be 0.4 and indeed it looks like it is. But the find command cannot find it. on the other hand it does find 0.3 0.7 etc. I multiplied the c by 1000 and looks like some of the values in it will be 300, 500 etc and some other values like 0.4 will be 400.000. I am not sure what is going on here. Is this a known bug? is there a fix for it?
Thanks, Maryam

Réponse acceptée

Arturo Moncada-Torres
Arturo Moncada-Torres le 1 Sep 2011
The problem is that you are trying to compare floating point numbers. This is clearly explained in the MATLAB FAQ. Also check this recent previous thread which addresses the same problem.
  1 commentaire
Maryam Vaziri Pashkam
Maryam Vaziri Pashkam le 2 Sep 2011
Thanks Arturo,
That was very helpful.
Maryam

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by