From: John D'Errico on
dpb <none(a)non.net> wrote in message <hrh9j6$v62$1(a)news.eternal-september.org>...
> dpb wrote:
> ...
>
> > >> tmp=A(A<B); lowinterpolant = tmp(end)
> > lowinterpolant =
> > 1992
> > >>
>
> Better...eliminates temporary
>
> max(A(A<B))

Also terribly poor for large problems, and still not
vectorized.

John
From: dpb on
John D'Errico wrote:
> dpb <none(a)non.net> wrote in message
....

>> I didn't see the trick to John's histc() answer--I'm sure there's
>> something obvious I'm overlooking.
>
> Look at the help for histc.
>
> A = [1990;1992;1996;1997;1998];
>
> [junk,index] = histc(1993,A);
....

Ah...that's what I wasn't thinking of; for some reason using the array
as the edges didn't strike me...

I don't disagree on the other comments; as said had a temporary blind
spot on histc()

--
From: John D'Errico on
dpb <none(a)non.net> wrote in message <hrhcih$eh3$1(a)news.eternal-september.org>...
> John D'Errico wrote:
> > dpb <none(a)non.net> wrote in message
> ...
>
> >> I didn't see the trick to John's histc() answer--I'm sure there's
> >> something obvious I'm overlooking.
> >
> > Look at the help for histc.
> >
> > A = [1990;1992;1996;1997;1998];
> >
> > [junk,index] = histc(1993,A);
> ...
>
> Ah...that's what I wasn't thinking of; for some reason using the array
> as the edges didn't strike me...
>
> I don't disagree on the other comments; as said had a temporary blind
> spot on histc()

For your reference, histc is the way that one would
decide which interval a point falls in when evaluating
a spline. There is a second decent solution, that uses
a tricky sort. It is also vectorized, and you may
occasionally find it in some older spline codes.

The only thing that must be watched for is if the point
in question falls outside of the bin edges for histc. This
is easily trapped though, by one of several schemes.

Years ago before histc existed, I put bindex on the FEX,
as a solution to this general problem. It is still there,
although I imagine it gets little use now except for
those people who are still living with version 4 or 5 of
matlab. Bindex used a scheme (out of 4 possibilities
provided) where it chose a method that was based on
the number of bins, the number of points etc.

John
First  |  Prev  | 
Pages: 1 2
Prev: regionprops
Next: regionprops