Macro and setresult

Hi,

could someone here please tell me why while doing this I end up with Dersec=Deriv, and not Dersec=profile (at least as displayed):

macro "Stack profile Data" {
run("Clear Results");
makeRectangle(0,150,1024,1);

profile = getProfile();
Deriv=profile;
Dersec=profile;

for (i=0; i<profile.length-1; i++) {

setResult("1", i, profile[i]);
Deriv[i]=profile[i+1]-profile[i];
setResult("2", i, Deriv[i]);
Dersec[i]=profile[i];
setResult("3", i, Dersec[i]);
}

}

Thanx
R.

Even if the macro language aims to make things as easy as possible, it can’t hide some properties of the underlying programming language, i.e. Java.

When setting

Deriv=profile;

you aren’t copying the contents of the array, but you make them reference the same contents.
So, when you’re changing

Deriv[i]=...

the content of profile[i] will change as well, because in fact they are the same.


Use

Deriv = Array.copy(profile)

instead (see the macro functions documentation).