help-octave
[Top][All Lists]
Advanced

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

Re: Question about indexing multi-dimensional matrices


From: Moreno Marzolla
Subject: Re: Question about indexing multi-dimensional matrices
Date: Sat, 06 Sep 2008 14:02:21 +0200
User-agent: Thunderbird 1.5.0.14ubu (X11/20080724)

Jaroslav Hajek wrote:
[...]
use a cs-list argument to achieve what you need:

adims = [3,3,4]
aind = [1,2,3]

aind = num2cell (aind);
ind = sub2ind (adims, aind{:})

Thank you very much, it works!
Actually, it is even better. Apparently I can use num2cell to index multidimensional matrices directly (instead of using a vector + sub2ind), like this:

N = [3 3 4];
A = zeros(N);
idx = [1 3 2];
iidx = num2cell(idx);
A( iidx{:} ) = 1;

Regards,

Moreno.

--
Moreno Marzolla
EMail: address@hidden
WWW  : http://www.pd.infn.it/~marzolla



reply via email to

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