For loop running only the first line in macro language. How to fix the issue?

Here is the piece of code:

open("/C:/Users/kh.csv")
//print(getResult("x1", 0));
  x1 = newArray(nResults);
  y1 = newArray(nResults);
  size=nResults;
for (ii=0; ii<size; ii++)
x1[ii] = getResult("x1", ii);
 y1[ii] = getResult("y1", ii);

Array.show(x1)
Array.show(y1)

I get his error:
image

but when I delete x1[ii] = getResult(“x1”, ii); line, y has the right values.

Hi @Zeynab_Mousavi,

you may just have forgotten some curly brackets:

open("/C:/Users/kh.csv")
//print(getResult(“x1”, 0));
x1 = newArray(nResults);
y1 = newArray(nResults);
size = nResults;
for (ii = 0; ii < size; ii++) {
    x1[ii] = getResult(“x1”, ii);
    y1[ii] = getResult(“y1”, ii);
}

Array.show(x1);
Array.show(y1);

You find more documentation here:
https://imagej.net/developer/macro/macros.html#loops

Cheers,
Robert

3 Likes

worked! thanks a lot!

1 Like