Thread Subject: even values

Subject: even values

From: remi

Date: 25 Jun, 2009 16:08:02

Message: 1 of 3

Hello all,...Please if i have a matix and i want to find out the amount of even coefficients it contains..
ie
B= [1 4 8 0 9 5
       7 2 6 1 2 4
       9 2 0 3 0 6]
i want to be able to count out that there are 8 even values of of the 18 values.
Thanks

Subject: even values

From: us

Date: 25 Jun, 2009 16:13:01

Message: 2 of 3

"remi " <obiosiki@yahoo.com> wrote in message <h207d1$ml6$1@fred.mathworks.com>...
> Hello all,...Please if i have a matix and i want to find out the amount of even coefficients it contains..
> ie
> B= [1 4 8 0 9 5
> 7 2 6 1 2 4
> 9 2 0 3 0 6]
> i want to be able to count out that there are 8 even values of of the 18 values.
> Thanks

this FEX submission may be helpful...

http://www.mathworks.com/matlabcentral/fileexchange/24278

us

Subject: even values

From: Nathan

Date: 25 Jun, 2009 16:18:10

Message: 3 of 3

On Jun 25, 9:08 am, "remi " <obios...@yahoo.com> wrote:
> Hello all,...Please if i have a matix and i want to find out the amount of even coefficients it contains..
> ie
> B= [1 4 8 0 9 5
>        7 2 6 1 2 4
>        9 2 0 3 0 6]
> i want to be able to count out that there are 8 even values of of the 18 values.
> Thanks

You do know that Zero is an even number, right?
Therefore.. that would be 11 even values...
%total elements minus odd elements
B = numel(B) - numel(find(mod(B,2)));

B will be the number of even elements.

Hope that's what you were looking for.

However, if you want Zero to not be counted, just set the zero values
to an odd number first:
B(find(B==0)) = 1;
and THEN do:
B = numel(B) - numel(find(mod(B,2)));

-Nathan

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
file exchange us 25 Jun, 2009 12:14:08
reference us 25 Jun, 2009 12:14:08
fex us 25 Jun, 2009 12:14:08
even values remi 25 Jun, 2009 12:09:09
rssFeed for this Thread

Contact us at files@mathworks.com