Login  Register

Re: macro creating n variables within a loop

Posted by Michael Doube-4 on May 12, 2014; 11:12am
URL: http://imagej.273.s1.nabble.com/macro-creating-n-variables-within-a-loop-tp5007692p5007694.html

Hi Tenorio,

You may be better off using an array and adding each item to the respective index.

e.g.

n = 100; //number of variables
array = newArray(n); //create the array

for (i = 0; i < n; i++){
  array[i] = <some calculated value>;
}

//use the values
result = array[17] * array[23]; //to use the values at the 23d and 17th indices

Note, unlike Matlab, IJ macro and Java are zero-indexed ('first'/zeroth element of an array is at array[0]).

Michael


On 12/05/14 11:55, Tenorio wrote:

> Dear all,
> I am trying to create variables automatically inside of a loop (sample1=1,
> sample2=2, sample3=3, ... sample x=x , like you can do in matlab with the
> sentence sample{x} = x), but I couldn't find the right code to do it in
> ImageJ.
>
> Any help would be greatly appreciated,
>
> Thanks in advance,
>
> Tenorio.
>
>
>
> --
> View this message in context: http://imagej.1557.x6.nabble.com/macro-creating-n-variables-within-a-loop-tp5007692.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

<http://www.rvc.ac.uk>

This message, together with any attachments, is intended for the stated addressee(s) only and may contain privileged or confidential information. Any views or opinions presented are solely those of the author and do not necessarily represent those of the Royal Veterinary College.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html