Posted by
L'assegnista on
Jan 10, 2021; 10:08am
URL: http://imagej.273.s1.nabble.com/Filling-an-Array-from-within-a-user-defined-function-in-Macro-Language-tp5024345p5024348.html
Dear all,
thank you very much for your quick and informative answers.
Indeed, all the suggestions solved my problem.
As I have many arrays it is less handy to add them in the function
arguments ( that is already crowded!) or as a return.
For this I will go with the Michael suggestion of defining the arrays as
global arrays, outside the function.
Thank you very much indeed to you all!!
Greetings
Federico
Il giorno dom 10 gen 2021 alle ore 07:52 Wayne Rasband <
[hidden email]>
ha scritto:
> > 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>
--
Federico Luzzati, PhD
Assistant Professor
University of Turin,
Dept. LIfe Sciences and Systems Biology (DBIOS)
Via Accademia Albertina, 13 - 10123 Torino - IT
Researcher at
Neuroscience Institute Cavalieri Ottolenghi (NICO)
Regione Gonzole, 10 - 10043 Orbassano (To) - IT
tel. +39-0116704683/ -6631
http://www.nico.ottolenghi.unito.it/index.php/it/adult-neurogenesisSostieni con il tuo 5xmille il NICO e la ricerca sulle malattie
neurodegenerative
Firma nel riquadro "Finanziamento della ricerca scientifica e
dell'Università"
CF 97564560015
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html