Re: Sum of all elements in array

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: Sum of all elements in array

William Nicolas
Thanks for the advice, it works just fine, I have also had another advice for a colleague, I will share it as it could be useful for others :

A=newArray(1,2,3,4,5);
Array.getStatistics(A,MIN,MAX,MEAN,STDDEV);
print(MEAN);
SumElements=MEAN*A.length;
print(SumElements);

It’s basically asking for the mean of the elements and then going backwards by multiplying by the number of elements in the array :)

Regards,

William

> Date:    Mon, 29 Dec 2014 12:22:20 +0000
> From:    Gabriel Landini <[hidden email]>
> Subject: Re: Sum of all elements in an array
>
> On Monday 29 Dec 2014 11:58:23 you wrote:
>> If I create an array :
>> A=newArray(1,2,3);
>> I would like to make operations on the 3 elements for instance summing or
>> multiplications (1+2+3 or 1*2*3 etc.)
>
> I would not be reasonable to expect every possible operation to have its own
> function. Just use the macro language:
>
> total=0;
> A=newArray(1,2,3);
> for (i=0;i<lengthOf(A);i++){
> total=total+A[i];
> }
> print (total);
>
> or use
> total=1; and  total=total*A[i];
> for the multiplication of the array entries.
>
> Cheers
>
> Gabriel
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>
> -----------------------------


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html