syntax of find

Jaroslav Hajek highegg at gmail.com
Sun Jun 7 01:21:15 CDT 2009


On Sat, Jun 6, 2009 at 11:34 PM, Thorsten Meyer<thorsten.meyier at gmx.de> wrote:
> In the documentation of cs-lists I find the following example:
>
> x = ceil (randn (10, 1));
> in = struct ("call1", {x, Inf, "last"},
>             "call2", {x, Inf, "first"});
> out = struct ("call1", cell (2, 1), "call2", cell (2, 1));
> [out.call1] = find (in.call1);
> [out.call2] = find (in.call2);
>
> With the current tip, it fails, because octave tries to allocate for an
> infinitely large return vector. I guess, that at some point, "inf" as the second
> input argument to find meant "all". By experimenting, I found that giving a
> negative number (or even -inf) instead of Inf will find all nonzero elements now.
>
> Is that compatible behaviour?
>
> What does matlab say to
>
> find([1, 0, 1, 0, 1], -1, "last")
>
> and
>
> find([1, 0, 1, 0, 1], inf, "last")
>
> ?
>
> Thanks
>
> Thorsten
>
>

Hmm. It seems at a certain point I missed the crucial fact that the
second arg to find gives a *maximum* number of indices, which is not
mentioned in the docs (although it's quite logical).
The docs were also misleading in that they said that "last" forces
"counting from the last one", which IMHO implies that the last index
should come first, which was apparently not true in 3.0.x (but is in
3.2.0).
Both bugs are fixed now, and docs improved.

thanks


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



More information about the Octave-maintainers mailing list