Re: Filling an Array from within a user defined function in Macro Language
Posted by
Wayne Rasband-2 on
Jan 10, 2021; 6:47am
URL: http://imagej.273.s1.nabble.com/Filling-an-Array-from-within-a-user-defined-function-in-Macro-Language-tp5024345p5024347.html
> On Jan 9, 2021, at 7:04 PM, Federico Luzzati <
[hidden email]> wrote:
>
> Dear List,
> I have a long macro that I tried to simplify using a function.
> The main purpose of this function was to fill a series of arrays that I'd
> like to save at the end of the macro.
> However I saw that arrays are not filled within functions and I was
> wondering if this could be possible.
Arrays can be filled in functions, as in this example:
a1 = newArray(5);
a2 = newArray(5);
fillArray(a1, 3);
Array.print(a1);
fillArray(a2, 7);
Array.print(a2);
function fillArray(a,v) {
Array.fill(a,v);
}
The output is:
3, 3, 3, 3, 3
7, 7, 7, 7, 7
-wayne
> I have very little knowledge of
> programming in general ( as you could have already understood!)
>
> Here a quick example that demonstrate what I would like to do
>
> Array1=newArray();
> Array2=newArray();
>
> for (i=0;i<5;i++){
> Array1=Array.concat(Array1,i);
> }
>
> function Array_fill(n){
> for(i=0;i<n;i++){
> Array2=Array.concat(Array2,i);
> }
> }
> Array_fill(5);
> print("Array1 length: "+Array1.length);
> print("Array2 length: "+Array2.length);
>
> Thank you very much
>
> Federico
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html