Login  Register

Re: Counting the number of elements in an array based on a set criteria

Posted by Herbie on Sep 04, 2017; 8:44am
URL: http://imagej.273.s1.nabble.com/Counting-the-number-of-elements-in-an-array-based-on-a-set-criteria-tp5019312p5019314.html

Good day wj,

I'm far from sure what you would like to achieve with your macro code
but this

        X = Array.concat(X, a[i]);

wont work!

(X as an argument is not known to the function. It is not defined.)

Please tell us what _exactly_ you expect as a result and BTW variable
scale is not defined as well.

Regards

Herbie


::::::::::::::::::::::::::::::::::::::
Am 04.09.17 um 04:35 schrieb wei.jian:

> Hi there,
>
> I'm working on a code that would enable me to count the number of elements
> that fulfil a particular type of criteria. Here's what I've but it seems
> that the array.concat function throws my code off if I've this code embedded
> in a loop. I.e. data from other channels are also concatenated. Can someone
> suggest an alternate method for me to make this work? In the e.g. below,
> I've set values that are equal or above 20 to be identified for counting.
>
> a = newArray(10, 20, 30, 40, 50, 40, 30, 20, 10);
>
> for (i=0; i<a.length; i++) {
> if (a[i]>=20) {
> X = Array.concat(X, a[i]);
> Y = Array.slice(X, 1, X.length);
> }
> }
> Array.show("Results", Y);
> print(Y.length/scale);
>
> Many thanks.
> wj
>
>
>
>
> --
> Sent from: http://imagej.1557.x6.nabble.com/
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

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