Saving array as a .txt file
Posted by Weller Andrew Francis on
URL: http://imagej.273.s1.nabble.com/Saving-array-as-a-txt-file-tp3702004.html
Dear all,
I have a folder of images that I am opening, analysing and saving the
results as a .txt file in a macro.
Say, for example, I have the following results saved as an array:
n = nResults;
ax = newArray(n);
ay = newArray(n);
for (j=0; j<n; j++) {
ax[j] = getResult("ax", j);
ay[j] = getResult("ay", j);
}
I then open a .txt file to save to where *all* results are saved:
f = File.open("/home/aweller/ImageJ/table.txt");
print(f, "Image_Name" + "\t" + "Area" + "\t" + "..." + "\n");
print(f, name + "\t" + area + "\t" + ... + "\n");
How can I append the array to this in an easy way so that I also save
each ax[j] and ay[j]?
I guess that I can have a for-loop somewhere as long as I don't start a
new line with the "\n" variable? Or does each time print(f, ...) closes,
it starts a newline?
I appreciate that I can do:
print(f, ax0 + "\t" + ax1 + "\t" + ax2 + "\t" ... + "\n");
but this seems slightly long-winded and I guess there a more 'automated'
way (in case my array size changes)?
Many thanks, Andy