Print function location in for loops

Hi all! I am having trouble printing out data from a batch image analysis- I have included the code below. I think I may be placing my print function in an improper location with the multiple for loops I have constructed, as I keep getting the error message
“undefined variable in line 35
print(ImageName,” “,GreenCounter,” “,NumberofGreen/NumberofCells*100);
line number is on clipboard”

It seems that it thinks my variables that I defined are undefined. Any help would be much appreciated!!
P.S I am very new to this so its probably a dumb mistake.

code9(language=IJ1 Macro):::

MyDirectory = getDirectory(“select the folder with the images”); //button to pick folder-leave as is
ListofFiles = getFileList(MyDirectory); //gets list of files from directory
ListofFiles = Array.sort(ListofFiles); //put list of files in order
NumberofFiles = ListofFiles.length; //get number of files in list

for (i=0; i<NumberofFiles; i++) {
run(“Bio-Formats Importer”, “open=[”+MyDirectory+ListofFiles[i]+"] color_mode=Composite view=Hyperstack stack_order=XYCZT");
run(“Split Channels”);
selectWindow(“C2-” + ImageName);
run(“Median…”, “radius=3”);
setThreshold(9772, 65535); //worked out tomato threshold
setOption(“BlackBackground”, true);
run(“Convert to Mask”);
run(“Analyze Particles…”, “size=10-Infinity clear add”); //count particles larger than 10 um
selectWindow(“C1-” + ImageName);
run(“Median…”, “radius=3”);
setAutoThreshold(“RenyiEntropy dark”);
run(“Set Measurements…”, “area_fraction limit redirect=None decimal=2”);
for(j=0;j<nResults;j++) {
if (data>50) {


print(ImageName,"	",GreenCounter,"	",NumberofGreen/NumberofCells*100);
run("Clear Results");
run("Close All");


Neither of those variables seem to be defined in your code.

1 Like

Thanks Gabriel! That fixed it! Looks like I had been looking at this thing for too long to realize that!