setResult is blank



I am tearing my hair out over this. I simply want to add a column to my results table with the filename in it so that i can link the measurement to the filename for analysis. The code below runs ok and writes the output files but the “label” column is blank and there is a final error message about test.xlsx being unsupported file.

dir1 = getDirectory("Choose Source Directory ");
dir2 = getDirectory("Choose Destination Directory ");
list = getFileList(dir1);

for (i=0; i<list.length; i++) {
 showProgress(i+1, list.length);
 title = getTitle;
 setResult("Label", nResults, title);
 run("Create Selection");


Not sure I understand your code, but shouldn’t this be
setResult("Label", i, title);
nResulst is the number of results in the table.
I suppose that you want to put the string in the nth, row?


Good day Gabriel,

works for me and has always worked for me:

mx = 10;
for ( i=0; i<mx; i++ ) { 
   str = d2s(i+0.1*(mx-i-1),1);
   setResult("Label", nResults, str);





Good day,

your macro code assumes several things:

  1. The images you are processing are really binary!
    Otherwise “run(“Create Selection”);” won’t work.
  2. “D://test/” is a valid directory.
    You don’t actually use “dir2”, do you?
  3. In Set Measuremenst “Area” is checked.
  4. At the end of your macro you need to include the line “setBatchMode(false);”.
  5. There may be more problems though.

Please learn how to correctly write ImageJ-macros and how to use the provided functions:




Hm… I see. Thanks.


Hi Andy!

Maybe you didn’t notice, but you can include the image title as a result column in Analyze > Set Measurement… under “Display Label”. It adds a “Label” column just beside the line numbering.

If you perform a measurement within a named Roi (either stored in RoiManager or just manually named), it outputs with following format: [FileName]:[RoiName]

You can ensure this behavior by default in your macro by adding a line setting the desired measurements and including the display parameter, like in:

run("Set Measurements...", "area mean display redirect=None decimal=3");

The easiest way to do it is just to launch the recorder, set these parameters, and then copy the output to your macro.



Thanks for all the help. I eventually solved it by incorporating some lines from a macro for measurement which was online. I think maybe the lines which helped are:

    if (getVersion>="1.40e")
        setOption("display labels", true);

I will take some time to learn the macro language properly before my next project!