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:
average the number on condtion at 1st column and count the no on some conditions

Subject: average the number on condtion at 1st column and count the no on some conditions

From: dibyendu

Date: 9 Jul, 2012 09:58:07

Message: 1 of 2

i have a matrix like this

A=[ 1 2 3; 2 3 3; 3 4 4; 4 5 3; 5 6 3; 6 8 4; 7 9 2; 8 5 4; 8 4 2]
now I want to average second column, condition is that if limit=0, and interval=3 and limit=limit+interval,, or in other words, i have to sum column 2 when values of column 1, ranges like 0 to 3, 3 to 6, 6 to 9, and 9 to 12, and also I need to count the no of 2, 3 or 4 in column 3 when the same ranges exist.

my solution will be like that

range-- avg (col 2) ( no if last col conditions)
                                           2 3 4
0 to 3 3 0 2 1
3 to 6 6.33 0 2 1
6 to 9 6 2 0 1


like that i have a matrix of arround 7000X3. in place of range just serial no may also be given.

this is just an example.

Subject: average the number on condtion at 1st column and count the no on some conditions

From: dibyendu

Date: 9 Jul, 2012 13:17:13

Message: 2 of 2

somebody reply plz

"dibyendu " <paldhere@gmail.com> wrote in message <jte9vf$3r7$1@newscl01ah.mathworks.com>...
> i have a matrix like this
>
> A=[ 1 2 3; 2 3 3; 3 4 4; 4 5 3; 5 6 3; 6 8 4; 7 9 2; 8 5 4; 8 4 2]
> now I want to average second column, condition is that if limit=0, and interval=3 and limit=limit+interval,, or in other words, i have to sum column 2 when values of column 1, ranges like 0 to 3, 3 to 6, 6 to 9, and 9 to 12, and also I need to count the no of 2, 3 or 4 in column 3 when the same ranges exist.
>
> my solution will be like that
>
> range-- avg (col 2) ( no if last col conditions)
> 2 3 4
> 0 to 3 3 0 2 1
> 3 to 6 6.33 0 2 1
> 6 to 9 6 2 0 1
>
>
> like that i have a matrix of arround 7000X3. in place of range just serial no may also be given.
>
> this is just an example.

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