[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Question about indexing multi-dimensional matrices
From: |
Przemek Klosowski |
Subject: |
Re: Question about indexing multi-dimensional matrices |
Date: |
Mon, 8 Sep 2008 14:40:25 -0400 (EDT) |
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;
Therefore, you can just wrap it up in a single line:
A(num2cell([1 2 3]){:})=2