Search All of the Math Forum:

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

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Finding position in array
Replies: 10   Last Post: Jun 6, 2014 6:42 PM

 Messages: [ Previous | Next ]
 dpb Posts: 9,850 Registered: 6/7/07
Re: Finding position in array
Posted: Jun 6, 2014 1:24 PM

On 6/6/2014 12:03 PM, Bruno Luong wrote:
>>
>> Yet another approach somewhat akin to Bruno's...
>>

>> >> interp1(a,1:length(a),x,'nearest')
>> ans =
>> 3

>
> Not completely equivalent, INTERP1 will has the resulting index jumps by
> 1 unit when passing the middle point of the EDGES, whereas HISTC jumps
> right at the EDGES.

Didn't say it was equivalent; only that it is "_somewhat_ akin to"...

> INTERP1 and HISTC methods can deal with x as vector (not FIND()).

But FIND() returns the specific preceding/following index value
depending on the usage if that's significant. The vector of lookup
values is easily dealt with via ARRAYFUN

>> x=[sqrt(x) x x.^1.5]
x =
2.9223 8.5400 24.9567
>> arrayfun(@(x) find(x>a,1,'last'),x)
ans =
1 3 4
>> arrayfun(@(x) find(x<a,1,'first'),x)
ans =
2 4 5
>>

--

Date Subject Author
6/5/14 Helveticus
6/6/14 dpb
6/6/14 Helveticus
6/6/14 dpb
6/6/14 Bruno Luong
6/6/14 dpb
6/6/14 Bruno Luong
6/6/14 dpb
6/6/14 Bruno Luong
6/6/14 dpb
6/6/14 Bruno Luong