Saving Results from "Plot Values" into Arrays in ImageJ Macro



Thank you for your feedback Dr. Swayne. It seems File O/I is the only way to go around it. I am just hoping it will not crash my system for the number of filed I will be generating (10,000…). I will look into the commands you suggested and try my best to achieve what I need by exploring other forums and resources before posting back again.



Upgrade to the latest ImageJ daily build and you will be able to use the Table.getColumn() macro function to retrieve a column from a table as an array. Here is an example:

   y1 = newArray(0, 0.7, 2.3, 2.8, 1.1, 0.5);
   y2 = newArray(0, 0.2, 0.6, 1.2, 2.2, 2.5);
   Plot.create("Simple Plot", "X", "Y");
   Plot.add("curve", y1);
   Plot.add("curve", y2);;
   Plot.showValues("Plot Values");
   col1 = Table.getColumn("Y0");
   col2 = Table.getColumn("Y1");

There are currently 19 Table.* functions. They operate on the current (frontmost) table or an optional title argument can be provided (e.g., Table.size(“My Table”)).

  • Table.create() - opens a new table
  • Table.reset() - resets (clears) the table
  • Table.size() - number of rows in the table
  • Table.title() - title of the current table
  • Table.headings() - column headings as a tab-delimited string
  • Table.get(columnName, rowIndex) - returns a numeric value
  • Table.getColumn(columnName) - returns a column as an array
  • Table.getString(columnName, rowIndex) - returns a string value
  • Table.set(columnName, rowIndex, value) - sets numeric or string value
  • Table.update() - updates table window
  • Table.applyMacro(macro) - applies macro code to table
  • Table.rename(title1, title2) - renames a table
  • - saves the table
  • - opens a table
  • Table.deleteRows(index1, index2) - deletes specified rows
  • Table.renameColumn(oldName, newName) - renames a column
  • Table.deleteColumn(columnName) - deletes specified column
  • Table.showRowNumbers(boolean) - enable/disable row numbers
  • Table.showArrays(titleAndOptions, array1, array2, ...) - displays arrays in a table (like



Thank you so much! Is this build 1.51w?


It is the latest daily build (1.52a51). Use the Help>Update ImageJ command and select “daily build” from the drop down menu.


Dear Dr. Rasband,

I am truly grateful to you for this update and advice. Hopefully this last question will really be my last. My entire table has 2080 rows but the X1 column only has 16 rows. When I run Table.getColumn(“X1”); and then print it to the log screen, I get my 16 values as expected followed by 2064 empty values. How do I account for these empty values such that my final array is only 16 in length and not 2080? I only want the 16 values (or how many ever real values exist in that column) and not the empty cells following those values. Any feedback on that would be sincerely appreciated.

Thank You,


Here is an example macro that runs “Find Peaks”, displays the “Plot Values” table and retrieves the X1 and X2 columns (requires ImageJ 1.52a52 or later):

   run("Find Peaks", "min._peak_amplitude=73.45 min._peak_distance=0");
   Plot.showValues("Plot Values");
   x1 = Table.getColumn("X1");
   x2 = Table.getColumn("X2");


Dear Dr. Rasband,

count = 0;
colCount = 0;
X_1 = Table.getColumn("X1");
	if(X_1[count] >= 0){
	} else {
		X_1[count] = NaN;
}while(count <= X_1.length-1) ;

I came up with this temporary fix which is giving me the appropriate value for colCount depending on which column I choose. I am also grateful to the alternate solution you just provided which gives me the flexibility to create new functions and learn how to define new functions in ImageJ macro. Thank you so much for your help. I feel I can take it from here. I am really grateful to you and everyone who has guided me on this topic.

Thank You,



I just realised computationally cost wise your method is far superior. Thank you so much for your help Dr. Rasband @Wayne


In the latest daily build (1.52a52), the Table.getColumn() method automatically removes (trims) unused elements from arrays.


It is nice to see the new table functions made available with the current daily build of ImageJ but of course the functionality is also achieved with functions that are available with older versions.

Here is the macro code that gets the desired arrays from a horizontal scan line:

l = getWidth();
h = getHeight()/6;
run("Plot Profile");
run("Find Peaks", "min._peak_amplitude=254.99 min._peak_distance=0 min._value=[] max._value=[]");
arrX_1 = newArray(nResults);
arrX_2 = newArray(nResults);
k = 0;
l = 0;
for ( i=0; i<nResults; i++ ) { 
	x1 = getResult("X1", i);
	x2 = getResult("X2", i);
	if ( !isNaN(x1) ) { arrX_1[i] = x1; k++; }
	if ( !isNaN(x2) ) { arrX_2[i] = x2; l++; }
arrX_1 = Array.trim(arrX_1, k);
arrX_2 = Array.trim(arrX_2, l);
// inspect the arrays"Inspect",arrX_1, arrX_2);

The code is based on my earlier suggestion.