Posted by
Lucas, Falk /BDF HAM on
Aug 02, 2006; 2:47pm
URL: http://imagej.273.s1.nabble.com/User-defined-functions-tp3701916p3701926.html
Hi Andy,
2 ways...
1) define out as variable in the beginning
var out="";
this will give you some kind of global variable.
2) using return values
main
...
result = myfunction();
...
function myfunction(){
...
out="whatever";
return out;
}
both ways should work...
Falk
BTW: Thx, for the focus macros on the wiki page!
-----Ursprüngliche Nachricht-----
Von: ImageJ Interest Group [mailto:
[hidden email]] Im Auftrag von Andy Weller
Gesendet: Mittwoch, 2. August 2006 15:22
An:
[hidden email]
Betreff: Re: User-defined functions
I have a user-defined function that does various measurements:
function measurements() {
some measurements
...
out = "";
out = Name + "," + area + "," + ...; // String container for all results return out; }
Now in my main macro it states that "out" is an "undefined variable", although I am returning it from function measurements()?!
macro "Test" {
dir1 = getDirectory("Choose Source Directory"); list = getFileList(dir1); numberFile = list.length; setBatchMode(true); compResults = newArray(numberFile); for (i=0; i<numberFile; i++) {
some stuff
...
measurements();
compResults[i] = out; // THIS IS WHERE IT BUMS OUT?!
}
Any clues out there?!
Thanks, Andy
On Wed, 2006-08-02 at 14:04 +0200, Andy Weller wrote:
> Dear all,
>
> I have built up a rather lengthy macro and am splitting it up into
> discrete user-defined functions for debugging simplicity.
>
> I think I understand how to operate them (from:
>
http://rsb.info.nih.gov/ij/developer/macro/macros.html#functions); can
> someone explain to me if I have the wrong idea please (regarding
> passing things to/from them really)?
>
> macro "Test" {
> open();
> img = getImageID();
> setAutoThreshold();
> run("Analyze Particles...", "size=5000-Infinity circularity=0.00-1.00
> show=Masks exclude clear include"); mask = getImageID; myfunction(img,
> mask); // Passes img and mask to function "myfunction"
> }
>
> function myfunction(img, mask) { // img and mask passed to "myfunction"
> some measurements on img and mask
> return results; // "results" returned to macro "Test"
> }
>
> Thanks, Andy
_____________________ Confidentiality _____________________
This electronic transmission is strictly confidential and intended
solely for the addressee. It may contain information which is covered
by legal, professional or other privilege. If you are not the intended
addressee, you must not disclose, copy or take any action in reliance
of this transmission. If you have received this transmission in error,
please notify us and delete the received data as soon as possible.
This footnote also confirms that this email message has been swept
for the presence of computer viruses.
_______________________________________________________