Discussion:
zero one indexing problem with Octave 3.2
(too old to reply)
Nigel Dodd
2011-02-19 19:41:03 UTC
Permalink
In one of the references about Octave it says
A special form of indexing may be used to select elements of a matrix or vector. If the indices are vectors made up of only ones and zeros, the result is a new matrix whose elements correspond to the elements of the index vector that are equal to one. For example,


a = [1, 2; 3, 4];
a ([1, 0], :)

selects the first row of the matrix a.


However when I do this I get the following error:

octave-3.2.4:1> a = [1, 2; 3, 4];
octave-3.2.4:2> a ([1, 0], :)
error: subscript indices must be either positive integers or logicals.

Has the zero-one indexing facility been removed in newer versions of Octave? Is there any workaround?
Thorsten Meyer
2011-02-19 20:53:06 UTC
Permalink
Post by Nigel Dodd
In one of the references about Octave it says
A special form of indexing may be used to select elements of a matrix or vector. If the indices are vectors made up of only ones and zeros, the result is a new matrix whose elements correspond to the elements of the index vector that are equal to one. For example,
a = [1, 2; 3, 4];
a ([1, 0], :)
selects the first row of the matrix a.
octave-3.2.4:1> a = [1, 2; 3, 4];
octave-3.2.4:2> a ([1, 0], :)
error: subscript indices must be either positive integers or logicals.
Has the zero-one indexing facility been removed in newer versions of Octave? Is there any workaround?
a(logical ([1,0]), :)

is probably what you are looking for.

regards

Thorsten

P.S.: the mailing list help-***@octave.org is a much better place to ask this
kind of question.
Nigel Dodd
2011-02-19 20:57:34 UTC
Permalink
thanks, Thorsten.
I have been searching for this for a while.

Loading...