macro creating n variables within a loop

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

macro creating n variables within a loop

Tenorio
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.
Reply | Threaded
Open this post in threaded view
|

Re: macro creating n variables within a loop

Michael Doube-4
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
Reply | Threaded
Open this post in threaded view
|

Re: macro creating n variables within a loop

Tenorio
Hi Doube,
Thank you for your answer. It was very useful for my macro.

Thank you.

Best regards.

Tenorio