Antwort: Re: How to define a 3D array?

Posted by Joachim Wesner on
URL: http://imagej.273.s1.nabble.com/How-to-define-a-3D-array-tp3695869p3695871.html

Mike,

what you suggest is not the same! Your arrays have a total of 30 elements,
the one that Sasmitha needs has 1000 elements!

Sasmitha,

You can“t really, there are not even 2D arrays in a macro, you needs to
create a single array of 1000 elements and use
explicit indexing, i.e, instead of

a[i][j][k]  (i, j, k, = 0..9)

use

a[i*100+j*10+k]

JW

ImageJ Interest Group <[hidden email]> schrieb am 17.06.2008 10:47:36:

> Sasmita:
>
> One (huckery) way that I've done this in a macro is to do something like:
>
> arrayX = newArray(10);
> arrayY = newArray(10);
> arrayZ = newArray(10);
>
> Which will give you 3 arrays with 10 empty elements that you can then
> retrieve using the same index:
>
> This snippet will list all your 3 dimensional positions.
> for (i = 0; i <10; i++){
>     print(arrayX[i], arrayY[i], arrayZ[i]);
> }
>
> So long as you keep your array indices synchronised your 3 arrays will
> represent 3D positions.
>
> Alternatives to 3D arrays suggested on the IJ website are to use
> setPixel() and getPixel() in a stack that's big enough to hold your
> data, or make a 1D array and do your own indexing:
> http://rsb.info.nih.gov/ij/developer/macro/functions.html#N
>
> You also don't have to declare your array as type int, the language will
> do that for you.
>
> Mike
>
> Sasmita Rath wrote:
> > Dear ImageJ Group,
> > Could you please tell me how to define a 3 dimensional array in a
macro.
> > I 'm using the syntax :
> > int name[][][]=new int [10][10][10];
> >
> >
> > but it's not working in ImageJ.
> >
> > Thank you.
> > Sasmita
> >


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________