Thread Subject:
Counting problem

Subject: Counting problem

From: Sepehr Sadighpour

Date: 19 Aug, 2010 15:27:22

Message: 1 of 4

I have a square matrix Z and need to count the number of elements within it that are a) smaller than 0.5, or b) greater than 179.5, and c) do not lie on the diagonal.

How would you recommend doing this? length(find(Z<0.5)) + length(find(Z>179.5) does the first two conditions, but how the third?

With thanks,
Sepehr

Subject: Counting problem

From: Sean

Date: 19 Aug, 2010 15:47:23

Message: 2 of 4

"Sepehr Sadighpour" <sepehr125@gmail.com> wrote in message <i4jigq$9av$1@fred.mathworks.com>...
> I have a square matrix Z and need to count the number of elements within it that are a) smaller than 0.5, or b) greater than 179.5, and c) do not lie on the diagonal.
>
> How would you recommend doing this? length(find(Z<0.5)) + length(find(Z>179.5) does the first two conditions, but how the third?
>
> With thanks,
> Sepehr

You could also do this:
sum(Z(:)<0.5)

One way:

New_Z = Z(~eye(length(Z)));
%Math on New_Z
 

Subject: Counting problem

From: Roger Stafford

Date: 19 Aug, 2010 16:07:23

Message: 3 of 4

"Sepehr Sadighpour" <sepehr125@gmail.com> wrote in message <i4jigq$9av$1@fred.mathworks.com>...
> I have a square matrix Z and need to count the number of elements within it that are a) smaller than 0.5, or b) greater than 179.5, and c) do not lie on the diagonal.
>
> How would you recommend doing this? length(find(Z<0.5)) + length(find(Z>179.5) does the first two conditions, but how the third?
>
> With thanks,
> Sepehr
- - - - - - -
count = nnz((Z<0.5|Z>179.5)&~eye(size(Z)));

Roger Stafford

Subject: Counting problem

From: Matt Fig

Date: 19 Aug, 2010 16:13:57

Message: 4 of 4

And another:
S = Z<.5 | Z>179.5;
count = sum(S(:)) - sum(diag(S))

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
counting Sepehr Sadighpour 19 Aug, 2010 11:29:36
rssFeed for this Thread

Contact us