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:
Calculate the number of a Single Element from a Matrix

Subject: Calculate the number of a Single Element from a Matrix

From: Nehal

Date: 23 Aug, 2010 17:05:21

Message: 1 of 3

I have a matrix which is 1x150 in size. The matrix contains random values from 1 to 15. No other values. So how can I count an element, for example "1", only from first 10 columns of that matrix? Not from the whole matrix.

Can anyone help me...?

Subject: Calculate the number of a Single Element from a Matrix

From: James Tursa

Date: 23 Aug, 2010 17:15:22

Message: 2 of 3

"Nehal " <arnab620@yahoo.com> wrote in message <i4u9oh$1uc$1@fred.mathworks.com>...
> I have a matrix which is 1x150 in size. The matrix contains random values from 1 to 15. No other values. So how can I count an element, for example "1", only from first 10 columns of that matrix? Not from the whole matrix.
>
> Can anyone help me...?

sum(X(1:10) == 1)

If that is not what you need, please give a more detailed explanation of what you want with a short example.

James Tursa

Subject: Calculate the number of a Single Element from a Matrix

From: Nehal

Date: 23 Aug, 2010 17:41:19

Message: 3 of 3

"James Tursa" <aclassyguy_with_a_k_not_a_c@hotmail.com> wrote in message <i4uaba$aii$1@fred.mathworks.com>...
> "Nehal " <arnab620@yahoo.com> wrote in message <i4u9oh$1uc$1@fred.mathworks.com>...
> > I have a matrix which is 1x150 in size. The matrix contains random values from 1 to 15. No other values. So how can I count an element, for example "1", only from first 10 columns of that matrix? Not from the whole matrix.
> >
> > Can anyone help me...?
>
> sum(X(1:10) == 1)
>
> If that is not what you need, please give a more detailed explanation of what you want with a short example.
>
> James Tursa

no need of any more example.. that is exactly what I needed. Thank You so much.

Tags for this Thread

No tags are associated with 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