[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Matrix index, Please e-mail back.

From: Jorgen Andersson
Subject: RE: Matrix index, Please e-mail back.
Date: Wed, 6 Dec 2006 08:33:04 -0800

Thanks to both of you.
My code works now!
I used one large index/mapping matrix 18432 x 32 to get to data in a 2048 x 9 matrix.
The time used to run the code changed from 180sec (for loop) to 10sec (index/mapping)!
John W Eaton wrotte:
"This happens because when you make a range using matrix values, only
| the first element of the matrix values are used.  In other words, if
| M1 and M2 are matrices, then the range _expression_ M1:M2 is equivalent
| to M1(1):M2(2).  Octave has this "feature" for compatibility with
| Matlab.
Do any of you know why it works like this? Is it a feature?
(I originally would have expected 3 ranges...)
ans = 1 2 3

From: Paul Kienzle [mailto:address@hidden
Sent: Tue 12/5/2006 6:16 PM
To: Jordi Gutierrez Hermoso
Cc: address@hidden; Jorgen Andersson
Subject: Re: Matrix index, Please e-mail back.

On Dec 5, 2006, at 6:39 PM, Jordi Gutierrez Hermoso wrote:

> There are cute little indexing hacks that can be accomplished if you
> remember that Octave stores matrices in Fortran column-major order. In
> other words, a matrix can be indexed by a single index as if it were
> one long vector.

The functions sub2ind and ind2sub hide the details, letting you
access an array element by element rather than by slices.

- Paul

reply via email to

[Prev in Thread] Current Thread [Next in Thread]