Login  Register

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

Posted by wei.jian on Sep 04, 2017; 2:35am
URL: http://imagej.273.s1.nabble.com/Counting-the-number-of-elements-in-an-array-based-on-a-set-criteria-tp5019312.html

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