0

I've got a huge array of values, all or which are much smaller than 1, so using a round up/down function is useless. Is there anyway I can use/make the 'find' function on these non-integer values?

e.g.

ind=find(x,9.5201e-007)

FWIW all the values are in acceding sequential order in the array.

Much appreciated!

0

3 Answers 3

2

The syntax you're using isn't correct.

find(X,k)

returns k non-zero values, which is why k must be an integer. You want

find(x==9.5021e-007);
%#   ______________<-- logical index: ones where condition is true, else zeros
%#   the single-argument of find returns all non-zero elements, which happens
%#   at the locations of your value of interest.

Note that this needs to be an exact representation of the floating point number, otherwise it will fail. If you need tolerance, try the following example:

tol = 1e-9; %# or some other value
val = 9.5021e-007;
find(abs(x-val)<tol);
Sign up to request clarification or add additional context in comments.

2 Comments

Excellent, I had tried the find(x==9.5021e-007); first but forgot the == (haven't been on my game today I guess...) I need one exact value so this works w/o tolerance. Thanks!
@tmpearce: for the last one: find( abs(x-val)<tol )
0

When I want to find real numbers in some range of tolerance, I usually round them all to that level of toleranace and then do my finding, sorting, whatever.

If x is my real numbers, I do something like

xr = 0.01 * round(x/0.01);

then xr are all multiples of .01, i.e., rounded to the nearest .01. I can then do

t = find(xr=9.22) 

and then x(t) will be every value of x between 9.2144444444449 and 9.225.

1 Comment

This would work I but I have so much data and I need an accurate index of the exact number I'm looking at. So I have no tolerance area.
0

It sounds from your comments what you want is

`[b,m,n] = unique(x,'first');

then b will be a sorted version of the elements in x with no repeats, and

x = b(n);

So if there are 4 '1's in n, it means the value b(1) shows up in x 4 times, and its locations in x are at find(n==1).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.