We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › multidimensional array access
Page Index Toggle Pages: 1
multidimensional array access (Read 518 times)
multidimensional array access
May 31st, 2006, 2:06am
 
is there a compact way in Java to extract slices from a multidimensional array without lots of looping? For example, let's say I have a 4D array

int[][][][] A = new int[7][2][4][8];

I know that you can extract slices starting at the beginning:

A[6]

yields a 3D array the same size as int[2][4][8], but what about, say, extracting a funny slice like

A[everything][1][everything][4]

? This is extremely compact in Matlab-- A(:,1,:,4) --and I'm wondering if each of the dozens of such invocations in my Matlab code is going to have to be replaced by a set of nested loops.

thanks,
neil
Re: multidimensional array access
Reply #1 - May 31st, 2006, 8:30am
 
Maybe you should do this with a class instead of an n-dimensional array?

Generally from my experience, anything beyond three dimensions gets rediculous, and often should be accomplished by something else. When you've got four or five dimensions in an array it might be time to re-think your design.

Just a thought!
Page Index Toggle Pages: 1