problem with making a very simple matrix

조회 수: 1 (최근 30일)
Maryam Vaziri Pashkam
Maryam Vaziri Pashkam 2011년 9월 1일
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

채택된 답변

Arturo Moncada-Torres
Arturo Moncada-Torres 2011년 9월 1일
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
Maryam Vaziri Pashkam
Maryam Vaziri Pashkam 2011년 9월 2일
Thanks Arturo,
That was very helpful.
Maryam

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by