Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Count all values larger than x

Subject: Count all values larger than x

From: adam

Date: 11 Aug, 2009 14:16:19

Message: 1 of 4

Hi everyone,

I'm trying to count how many times the value e.g. 5 in a variable is exceeded.

So if I have a variable with the numbers 3,8,4,7,1,1 in it I want to count how many times a value is larger than e.g. 5 > it should return 2 in this case.

Is there such a function available in MATLAB?

Thanks,
Adam

Subject: Count all values larger than x

From: Dave Brackett

Date: 11 Aug, 2009 14:26:04

Message: 2 of 4

"adam " <unique.pq@gmail.com> wrote in message <h5rufj$h0g$1@fred.mathworks.com>...
> Hi everyone,
>
> I'm trying to count how many times the value e.g. 5 in a variable is exceeded.
>
> So if I have a variable with the numbers 3,8,4,7,1,1 in it I want to count how many times a value is larger than e.g. 5 > it should return 2 in this case.
>
> Is there such a function available in MATLAB?
>
> Thanks,
> Adam

a=[3,8,4,7,1,1]
b=a>5
c=sum(b)

Subject: Count all values larger than x

From: dpb

Date: 11 Aug, 2009 15:08:04

Message: 3 of 4

Dave Brackett wrote:
> "adam " <unique.pq@gmail.com> wrote in message
> <h5rufj$h0g$1@fred.mathworks.com>...
...
>> I'm trying to count how many times the value e.g. 5 in a variable
>> is exceeded.
...
>> Is there such a function available in MATLAB?
>>
>> Thanks, Adam
>
> a=[3,8,4,7,1,1] b=a>5 c=sum(b)
 > b=a>5
 > c=sum(b)

Which can be reduced to

n = s(a>b)

(recognizing perhaps intentional pedagogical approach)

--

Subject: Count all values larger than x

From: adam

Date: 11 Aug, 2009 17:34:19

Message: 4 of 4

Thank you both,

I'm using the shortr n=sum(a>b) and it works perfectly

Tags for this Thread

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.

Contact us