Hi,
I am writing a macro, where I create a newArray() to store names of all the open files. When I run Combine... command to combine the first two files (array elements [0] and [1]) as: run("Combine...", "stack1=&filenames[0] stack2=&filenames[1]"); It gives me an error "filenames[0] is not a valid choice for Stack1". But, if I assign the array elements to different variables and pass those variables, then it works: a = filenames[0]; b = filenames[1]; run("Combine...", "stack1=&a stack2=&b"); Is there a way to pass array elements as options to the run command? Thanks, Ved ________________________________ Ved Sharma, PhD Department of Anatomy and Structural Biology Albert Einstein College of Medicine Bronx, New York -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Since I did not see another reply, I will suggest something.
On 8/23/15 6:21 AM, Ved Sharma wrote: > Hi, > > I am writing a macro, where I create a newArray() to store names of all the open files. When I run Combine... command to combine the first two files (array elements [0] and [1]) as: > > run("Combine...", "stack1=&filenames[0] stack2=&filenames[1]"); > > It gives me an error "filenames[0] is not a valid choice for Stack1". But, if I assign the array elements to different variables and pass those variables, then it works: > > a = filenames[0]; > b = filenames[1]; > run("Combine...", "stack1=&a stack2=&b"); > > Is there a way to pass array elements as options to the run command? Try the "old fashioned" way: run("Combine...", "stack1="+filenames[0]+" stack2="+filenames[1]); This explicitly builds the string, and does not depend on the parser's ability to understand &filenames[0] > Thanks, > > Ved > ________________________________ > Ved Sharma, PhD > Department of Anatomy and Structural Biology > Albert Einstein College of Medicine > Bronx, New York > > -- Aryeh Weiss Faculty of Engineering Bar Ilan University Ramat Gan 52900 Israel Ph: 972-3-5317638 FAX: 972-3-7384051 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Make a loop that adds elements to a string. Then put the string in the run command.
Like this var thresholds = newArray(16, 32, 48, 64, 80); // some other stuff here, then... outputString = ""; for (t=0; t<thresholds.length; t++) { for (z=0; z<a.length; z++) { if ( (a[z]<thresholds[t]) || (b[z] < thresholds[t]) ) { a[z] = 0; b[z] = 0; } } coef = calculateCoefficient(a, b); outputString = outputString + coef + " \t "; } // for t, report at each threshold print (outputString); _________________________________________ Michael Cammer, Optical Microscopy Specialist http://ocs.med.nyu.edu/microscopy http://microscopynotes.com/ Cell: (914) 309-3270 ________________________________________ From: ImageJ Interest Group [[hidden email]] on behalf of Aryeh Weiss [[hidden email]] Sent: Sunday, August 23, 2015 12:17 PM To: [hidden email] Subject: Re: macro - array elements as options in run() Since I did not see another reply, I will suggest something. On 8/23/15 6:21 AM, Ved Sharma wrote: > Hi, > > I am writing a macro, where I create a newArray() to store names of all the open files. When I run Combine... command to combine the first two files (array elements [0] and [1]) as: > > run("Combine...", "stack1=&filenames[0] stack2=&filenames[1]"); > > It gives me an error "filenames[0] is not a valid choice for Stack1". But, if I assign the array elements to different variables and pass those variables, then it works: > > a = filenames[0]; > b = filenames[1]; > run("Combine...", "stack1=&a stack2=&b"); > > Is there a way to pass array elements as options to the run command? Try the "old fashioned" way: run("Combine...", "stack1="+filenames[0]+" stack2="+filenames[1]); This explicitly builds the string, and does not depend on the parser's ability to understand &filenames[0] > Thanks, > > Ved > ________________________________ > Ved Sharma, PhD > Department of Anatomy and Structural Biology > Albert Einstein College of Medicine > Bronx, New York > > -- Aryeh Weiss Faculty of Engineering Bar Ilan University Ramat Gan 52900 Israel Ph: 972-3-5317638 FAX: 972-3-7384051 -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html ------------------------------------------------------------ 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 |
In reply to this post by ved sharma
Hi Aryeh,
Thanks for your reply! The "old fashioned" way: run("Combine...", "stack1="+filenames[0]+" stack2="+filenames[1]); ... does not work directly, because in my case filenames[] strings contain spaces. I got it to work by including square brackets as follows: run("Combine...", "stack1=["+filenames[0]+"] stack2=["+filenames[1]+"]"); ... which is OK except I found it a little cumbersome to match all the opening and closing square brackets. Would be much simpler if &filenames[] works! Ved ________________________________ Ved Sharma, PhD Department of Anatomy and Structural Biology Albert Einstein College of Medicine Bronx, New York -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi all,
I have the same problem of Ved but in my case the array is a sequence of number that I would like to use in a run command. Very short, something like: t = newArray(0, 30, 60, 90); for (i=0, i++) { run("Translate...", "interpolation=None slice y=sin(t[i]) x=cos(t[i]"); } By using &t[i] there is no way to execute the Macro properly. If I use "+t[i]+" then the value number is read as a string and cannot perform my operation. Anyone have any clue how to do this? Thanks. Gabriele |
Hi Gabriele,
you have to use string concatenation in the correct way. The 'y=' and 'x=' are parts of the option string, the values you want to assign are given by the sin() function: t = newArray(0, 30, 60, 90); for (i=0; i<t.length; i++) { run("Translate...", "interpolation=None slice y=" + sin(t[i]) + " x=" + cos(t[i]) ); } Hope that helps, Jan On 28.01.2016 12:30, karvek wrote: > Hi all, > > I have the same problem of Ved but in my case the array is a sequence of > number that I would like to use in a run command. > > Very short, something like: > t = newArray(0, 30, 60, 90); > for (i=0, i++) { > run("Translate...", "interpolation=None slice y=sin(t[i]) x=cos(t[i]"); > } > > By using &t[i] there is no way to execute the Macro properly. > If I use "+t[i]+" then the value number is read as a string and cannot > perform my operation. > > Anyone have any clue how to do this? > Thanks. > > Gabriele > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |