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 number of cells in a Matrix

Subject: Count number of cells in a Matrix

From: Jie

Date: 2 Sep, 2009 08:35:04

Message: 1 of 3

Hello,

Could anyone help on this please?

Say I have a Matrix below as an example:

1 2 3
4 5 6
7 8 9

I want to know how many cells are smaller than 7 inside of this matrix?

Many Thanks in Advance.

Jie

Subject: Count number of cells in a Matrix

From: Aurelien Queffurust

Date: 2 Sep, 2009 08:47:02

Message: 2 of 3

"Jie " <jz286@cam.ac.uk> wrote in message <h7lano$7qj$1@fred.mathworks.com>...
> Hello,
>
> Could anyone help on this please?
>
> Say I have a Matrix below as an example:
>
> 1 2 3
> 4 5 6
> 7 8 9
>
> I want to know how many cells are smaller than 7 inside of this matrix?
>
> Many Thanks in Advance.
>
> Jie

A is your matrix, you can use :
>> numel(A(A<7))

Subject: Count number of cells in a Matrix

From: Dave Brackett

Date: 2 Sep, 2009 08:51:03

Message: 3 of 3

"Jie " <jz286@cam.ac.uk> wrote in message <h7lano$7qj$1@fred.mathworks.com>...
> Hello,
>
> Could anyone help on this please?
>
> Say I have a Matrix below as an example:
>
> 1 2 3
> 4 5 6
> 7 8 9
>
> I want to know how many cells are smaller than 7 inside of this matrix?
>
> Many Thanks in Advance.
>
> Jie

a=[1 2 3;4 5 6;7 8 9]
b=sum(sum((a<7)))

hope that helps

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