help-octave
[Top][All Lists]
Advanced

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

Disaggregating input arguments for sub2ind


From: Nir Krakauer
Subject: Disaggregating input arguments for sub2ind
Date: Wed, 19 Feb 2014 08:38:48 -0500

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

reply via email to

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