Posted by
Michael Schmid on
Oct 05, 2016; 9:48am
URL: http://imagej.273.s1.nabble.com/Creating-n-arrays-in-a-loop-tp5017287p5017289.html
Hi Matt,
you can't have arrays of arrays or 2D arrays in the ImageJ macro
language. The way out is flattening it out, so you have a longer 1D array:
arrayLength=5;
a = newArray(channels*arrayLength);
for (i=0; i<channels; i++)
a[i*arrayLength + 2] = someValueForArrayElement2;
In other words, array elements 0-4 correspond to the first channel
(i=0), 5-9 to the next channel (i=1), etc.
Michael
________________________________________________________________
On 2016-10-05 11:14, PEARSON Matthew wrote:
> Hi all,
>
> I must be having a mental block but i can't think how to define a variable number of arrays within a loop. I'm looking for a way for the loop to be able to create a number of arrays based on a counter variable. So something like:
>
> channels = could be any number;
> array length = 5; (this is always known)
> for (i=0; i<channels; i++) {
> newArray = Ch + i [array length]
> }
>
> I'd like the newly defined arrays to have the same name "Ch" plus an incremental number which comes from "i" but i don't know how to declare the array name to have a variable included. Is this possible in the macro language? I did a google search and came across a thread where someone had suggested importing the java utility "array list" but this looked like quite a complicated solution.
>
> Thanks for the help,
>
> Matt
>
>
> --
> Matt Pearson
> Microscopy Facility
> MRC Human Genetics Unit
> Institute of Genetics and Molecular Medicine (IGMM)
> University of Edinburgh
> Crewe Road
> EH4 2XU
>
>
>
>
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>
>
>
> The University of Edinburgh is a charitable body, registered in
> Scotland, with registration number SC005336.
>
> --
> ImageJ mailing list:
http://imagej.nih.gov/ij/list.html>
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html