Re: How to define a 3D array?

Posted by Michael Doube on
URL: http://imagej.273.s1.nabble.com/How-to-define-a-3D-array-tp3695869p3695870.html

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
>