help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: find command sometimes doesn't work in script


From: Jaroslav Hajek
Subject: Re: find command sometimes doesn't work in script
Date: Wed, 11 Nov 2009 21:39:13 +0100



On Wed, Nov 11, 2009 at 6:12 PM, Lidia Bressan <address@hidden> wrote:
I am havig problems with find.

I use ubuntu and I just upgraded to 9.10 Karmic Koala ubuntu.

I use 'find' to look for a particular value in a matrix, inside a for
loop.
Values of matrix B column 5 go from 1.0 to 5.0 (or to 4.0) with 0.05
step. Some values might be repeated.
I want to check where in matrix B, column 5 there are more times the
same value. In that case, I want to select the row with the smallest
positive value of column 6, and compose in this way matrix C.

The problem is that for some values 'find' in script doesn't work and
return an empty vector, while in terminal I get the right result.
Is there an error in my for loop or what could be the problem? Matrix B
is composed reading some files and then rearranging it.

Here after I write the code I use.

Do you have any suggestions, please?



In script:

 C=[];
 if( (max(BB(:,5))-min(BB(:,5)))/0.05 +1!=size(BB,1))

   for jj=1.0000:0.0500:max(BB(:,5))
       clear doubleval; doubleval=find(BB(:,5)==jj);
       if(size(doubleval,1)>1)
          clear rbay rbax
          mval=min(max(BB(doubleval,6),0));
          mvalx=find(BB(doubleval,6)==mval);
          C=[C; BB(doubleval(mvalx),:)];
       elseif(size(doubleval,1)==1)
          C=[C; BB(doubleval,:)];
       elseif(size(doubleval,1)==0)
          disp(jj)
       endif
   endfor
 else
    C=BB;
 endif


 1.6500
 1.9000
 2.0500
 2.3000
 2.5500
 2.8000
 3.0500
 3.3000
 3.4000
 3.5500
 3.6500
 3.8000
 3.9000
 4.1000
 4.3500
 4.6000
 4.8500


In terminal:

octave:102> jj=2.05;
octave:103> doubleval=find(BB(:,5)==jj)
doubleval = 58

Lidia Bressan

this looks like precision issue. What does

any ((1:0.05:5) == 2.05)

give you? You should be aware that numbers like 2.05 cannot be represented exactly by computer floating point types.

In any case it would help if you submitted a more complete report, including your Octave version & configuration, and if possible also the matrix BB that shows the problem.

hth

--
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz

reply via email to

[Prev in Thread] Current Thread [Next in Thread]