[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Disaggregating input arguments for sub2ind
From: |
Juan Pablo Carbajal |
Subject: |
Re: Disaggregating input arguments for sub2ind |
Date: |
Wed, 19 Feb 2014 15:39:07 +0100 |
On Wed, Feb 19, 2014 at 2:38 PM, Nir Krakauer <address@hidden> wrote:
> Dear all,
>
> I have an n-D grid whose size is given by grid_size, and an array of
> subscripts with size npoints*ndims, for example:
>
> grid_size = [5 4];
> grid_subs = [1 4; 5 1; 3 2];
>
> What's a general way to convert the subscripts to single indices, achieving
> the same result as, for example,
> grid_inds = sub2ind (grid_size, grid_subs(:, 1), grid_subs(:, 2)); #2-D case
> grid_inds = sub2ind (grid_size, grid_subs(:, 1), grid_subs(:, 2),
> grid_subs(:, 3)); #3-D case
> if the number of dimensions in the grid may vary between calls?
>
> Nir
>
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://mailman.cae.wisc.edu/listinfo/help-octave
>
Nir,
Besides having eval statement with the parametrized string, I
wouldn't know any other way, since it seems sub2ind doesn't accept
zipped arguments... something like the **kargs in python.
I hope Jordi corrects me on this.