[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question about indexing multi-dimensional matrices
From: |
Jaroslav Hajek |
Subject: |
Re: Question about indexing multi-dimensional matrices |
Date: |
Sat, 6 Sep 2008 14:33:32 +0200 |
On Sat, Sep 6, 2008 at 2:02 PM, Moreno Marzolla
<address@hidden> wrote:
> 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,
Yes, of course. This is called "Fortran" or "linear" indexing and is,
by default, available for any array.
>
> Moreno.
>
> --
> Moreno Marzolla
> EMail: address@hidden
> WWW : http://www.pd.infn.it/~marzolla
>
>
--
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz