Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: find
Replies: 2   Last Post: Mar 3, 2013 7:48 PM

 Messages: [ Previous | Next ]
 Derek Goring Posts: 3,920 Registered: 12/7/04
Re: find
Posted: Mar 3, 2013 7:48 PM

On Monday, March 4, 2013 1:28:25 PM UTC+13, Nasser M. Abbasi wrote:
> On 3/3/2013 5:10 PM, a h wrote:
>

> > Hey yall
>
> >
>
> > So i have vektor, and i want to find the position in the vektor where
>
> >the value is 50.2, but matlab keeps telling me
>
> >
>
> >>> find(x,50.2)
>
> > ??? Error using ==> find
>
> > Second argument must be a positive scalar integer.
>
> >
>
> >
>
> > what to do??,
>
> >
>
>
>
> http://www.mathworks.com/help/matlab/ref/find.html
>
>
>
> "
>
> ind = find(X, k) or ind = find(X, k, 'first') returns at most the first
>
> k indices corresponding to the nonzero entries of X. k must be
>
> a positive integer, but it can be of any numeric data type."
>
>
>
>
>
> may be you need find(x==50.2) instead

As Nasser points out, you've got the syntax wrong, but on top of that, since you're using floating point numbers, you should use:
find(abs(x-50.2)<tol)
where tol is a tolerance, say 1e-6.
The reason is explained here:
http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F

Date Subject Author
3/3/13 Nasser Abbasi
3/3/13 Derek Goring