Creating multiple arrays in for loop

Is tere a way to create multiple arrays in a for loop each one later containg one column from text image via getPixel() function?
The case is that I have my data from ROI measurements which later I’d like to plot, so each colmn in text image is a seprate yValues for plot, so I would like to extrac them and plot on graph. How one could do such a thing?

Best regards

Hello Szymon -

I’m not entirely sure what you want to do. What do you mean by
“text image?” Do you imagine writing a “for loop” in a java plugin?
In a script? In an ImageJ Macro (IJM)?

If you want to plot the values of pixels in vertical columns of an
image, and you prefer IJM, the simplest way might be to create
line ROIs, call getProfile(), and use IJM’s Plot Functions to
plot the resulting arrays.

Here’s an example:

run ("Blobs");
for (x = 0; x < getWidth(); x += 32) {
    makeLine(x, 0, x, getHeight() - 1);
    col = getProfile();
    if (x == 0) {
        Plot.create ("A_plot", "y", "pixel value", col);
    else {
        Plot.add ("line", col);
saveAs ("PNG", "A_plot.png");

And here is the resulting plot (as a png image):

Thanks, mm

Sorry I wasn’t that specific.
So the thing is that in the IJ macro I’m creating multiple ROIs (user specifies the number so sometimes is 3 and sometimes is 20 ect.) and measure them using multi measure function from ROIManager. Then the results are being saved in “.CSV” file, so each column of such file is the data set for one specific ROI and now I want to plot this data on one graph.
So depending on number of ROIs specified by user it would be graph consisting of different number of curves each for one ROI.
That’s why I was asking for creating multiple arrays in a for loop, one array for each column of the .CSV file, that will be later passed to function Plot.Add(x, y_n) where y_n is nth array thus nth column of CSV file.

Best regards

Hello Szymon -

As I understand it, you would like to use ImageJ and an IJ Macro
to open a text file that is on disk and plot each column of that file
as a separate curve all on one plot.

You should be able to use, Table.getColumn(),
and the Plot Functions to do this.

Here is an IJ Macro example:

// make a text file
newImage ("ramp", "8-bit ramp", 32, 32, 1);
run ("Duplicate...", " ");
run("Rotate 90 Degrees Right");
imageCalculator("Average create", "ramp","ramp-1");
saveAs ("Text Image", "ramp_text.txt");

// open the text file as a table ("ramp_text.txt");

// plot the columns
for (c = 1; c <= 32; c++) {
    col = Table.getColumn ("C" + c);
    if (c == 1) {
        Plot.create ("ramp_plot", "row", "pixel value", col);
    else {
        Plot.add ("line", col);
saveAs ("PNG", "ramp_plot.png");

And here is the resulting plot (png):

Thanks, mm

Thanks a lot,
I’ve already managed to do so using your previous method.
However, is it possible to iteratively change the color and the legend, I’ve already tried used this approach:

function PLOT (array)

fileB = array[3];
fileS = array[1];

run(“Text Image… “, “open=&fileB “);
id_text_Back =getImageID;
print(“slice” +”,”+ “Av.sign.” +”,”+ " Av.back." +","+ “difference”);

	for(j=0; j<array[2]; j++)

	average_Back[i]=(1/array[2]) *row_val[i] ;



//ImageJ macro languge does not support 2d arrays so measuremtns are opened as text image
run("Text Image… ", "open=&fileS ");
id_text_Sign =getImageID;
colors = newArray(“red”, “blue”, “green”, “black”, “cyan”, “darkGray”, “gray”, “lightGray”, “magenta”, “orange”, “pink”, “yellow”, “darkRed”, “orange”);

Plot.create("Change in differencial intensity", "Time delay [ps]", "Differencial Intensity [a.u]");


makeLine(i, 0, i, h - 1);
	col = getProfile();

	col[j] = col[j]-average_Back[j];
legend[i] = label;
Plot.add ("connected circle",x, col);


But there is always a problem caling colors[i] - when i put specific colors[0] everything works, but when I want to change the color in iterative mannerso every column would had its on color on the graph it gives an error…

How could I solve this?
Same with the legend…

Best regards