Posted by
Cammer, Michael on
Jul 10, 2016; 4:05pm
URL: http://imagej.273.s1.nabble.com/writing-results-of-different-length-into-columns-tp5016837p5016842.html
I use this method a lot. And adding another loop around the for i loop allows for adding columns to the outputString for each row incrementally. Example output of the version below at
https://www.flickr.com/photos/mcammer/28185160856/
This example generates a sequence of ten positive integers less than 100 and leaves the field blank if less than or equal to threshold value. In the Log window the numbers don't look aligned, but the tabs are there and get copied (or save as text and then open) into your favorite spreadsheet or stats program.
/* This method reinvents the table methods for on the fly use in the Log or other text output windows */
threshold = 16;
outputString = ""; // this could also be outputString = newArray(length); and fill with ""
for (i=0; i<10; i++) {
result = round(random() * 100);
if (result > threshold)
outputString = outputString + result + " \t";
else
outputString = outputString + " \t";
}
print (outputString);
_________________________________________
Michael Cammer, Optical Microscopy Specialist
http://ocs.med.nyu.edu/microscopyhttp://microscopynotes.com/Cell: (914) 309-3270
________________________________________
From: ImageJ Interest Group [
[hidden email]] on behalf of Volko Straub [
[hidden email]]
Sent: Sunday, July 10, 2016 2:11 AM
To:
[hidden email]
Subject: Re: writing results of different length into columns
Dear Sylvia,
I don't have a direct solution for your problem, but rather than writing
each selection co-ordinate pair directly into a results table (I assume
that is what you are doing), why don't you keep co-ordinates in a
one-dimensional array? You have then somewhat more flexibility how to
print the coordinates at the end of your macro. The code below prints
the coordinates into a text window in a format that can easily be copied
to Excel and split into columns where missing coordinates are shown as
empty cells. I think that is what you wanted.
The example has just two pairs of x/y coordinates (total of 4 arrays),
but it could easily be extended to more pairs. You can also write a
small macro function to dynamically add values to an array so that you
don't have to define the length of the required array at the start of
the macro. For examples, see:
https://urldefense.proofpoint.com/v2/url?u=http-3A__www.richardwheeler.net_contentpages_text.php-3Fgallery-3DImageJ-5FMacros-26file-3DArray-5FTools-26type-3Dijm&d=CwIC-g&c=j5oPpO0eBH1iio48DtsedbOBGmuw5jHLjgvtN2r4ehE&r=oU_05LztNstAydlbm5L5GDu_vAdjXk3frDLx_CqKkuo&m=SN__168OD-1g6I_woOqyXQGvv3oXxH-zYU1-THoPnSw&s=xplI8Y6HwkrgS-NF2dGYjnKXJiAE-JxoRvKJlJW322U&e=Hope this helps,
Volko
x1=newArray(2,4);
y1=newArray(7,5);
x2=newArray(1,4,10);
y2=newArray(8,10,5);
maxArrayLength=maxOf(x1.length,x2.length);
title1 = "Result Window";
title2 = "["+title1+"]";
f = title2;
if (isOpen(title1)){
print(f, "\\Update:"); // clears the window
}else{
run("Text Window...", "name="+title2+" width=72 height=8 menu");
};
for(i=0;i<maxArrayLength;i++){
if(i<x1.length){
print(f,x1[i]+", "+y1[i]);
}else{
print(f,", ");
};
if(i<x2.length){
print(f,", "+x2[i]+", "+y2[i]);
}else{
print(f,", ");
};
print(f,"\n");
};
On 09/07/2016 23:28, Sylvia Neumann wrote:
--
ImageJ mailing list:
https://urldefense.proofpoint.com/v2/url?u=http-3A__imagej.nih.gov_ij_list.html&d=CwIC-g&c=j5oPpO0eBH1iio48DtsedbOBGmuw5jHLjgvtN2r4ehE&r=oU_05LztNstAydlbm5L5GDu_vAdjXk3frDLx_CqKkuo&m=SN__168OD-1g6I_woOqyXQGvv3oXxH-zYU1-THoPnSw&s=z4AoOr0QkD3zN47h3P6vIOcq_MLcUN5rwU6TDZ_Z7n8&e=------------------------------------------------------------
This email message, including any attachments, is for the sole use of the intended recipient(s) and may contain information that is proprietary, confidential, and exempt from disclosure under applicable law. Any unauthorized review, use, disclosure, or distribution is prohibited. If you have received this email in error please notify the sender by return email and delete the original message. Please note, the recipient should check this email and any attachments for the presence of viruses. The organization accepts no liability for any damage caused by any virus transmitted by this email.
=================================
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html