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:
helppppp...summation of the corresponding data

Subject: helppppp...summation of the corresponding data

From: SM

Date: 17 Dec, 2011 20:46:08

Message: 1 of 10

for the same values in column 2, I want to do sum up the corresponding value in column 3 and replace them in corresponding column 4, if the difference between the corresponding value in column 1 is less than TOL, I made it in a following way...

A=[ 1 1 1 0
      2 1 1 0
      7 1 6 0
     15 1 7 0
      1 3 6 0
      2 3 6 0
      1 4 1 0
      3 4 7 0
     15 4 2 0];

INDEX=unique(A(:,2));
for i=1:length(INDEX);
index= A(:,2)==INDEX;
x=A(index,1);
y=A(index,3);
z=A(index,4);
for j=2:length(x)
if x(i)-x(i-1)<=TOL
A(index,4)=sum(x(i-1:i))
end
end
end

Assuming TOL=2, then output B shall be
B=[ 1 1 1 2
      2 1 1 2
      7 1 6 6
     15 1 7 7
      1 3 6 12
      2 3 6 12
      1 4 1 8
      3 4 7 8
     15 4 2 2];

But it doesnt work...can you advise me on how to solve this problem'?
thanks in advance

Subject: helppppp...summation of the corresponding data

From: ImageAnalyst

Date: 18 Dec, 2011 00:26:31

Message: 2 of 10

So the rows with 1 in col 2, they have 1,1,6,7 in col3, which adds to
15, yet none of the column 4's for the rows where col2=1 have 15 in
them. Can you explain why? I didn't understand the difference with
TOL thing - you just said to put the sum of col3 into col4 so what
difference are you talking about?

Subject: helppppp...summation of the corresponding data

From: SM

Date: 18 Dec, 2011 00:58:08

Message: 3 of 10

Dear Image analyst...
the one i gave was just example to explain what I want to do.

In fact, I have my data stored in a matrix in which first column represents the time (day) and 2nd column represents group#, and column 3 represents the representative value for each group in time.

I want to calculate the underlying trend over time for the representative value for each group. for trending, I want to group the data for instance every 3 days, that means that I for each group I sum up the Representative for 3 days and replace them in the forth column.'Because I need my data in 3rd column for later stages so, i don't want to touch them....

And afterwards, I want to calculate the trending, in a way that the data for current time (3days) minus the one for previous time (3days).


so what I did, I sort my data based on the group number. and tried to manipulate the data further...but I didnt make it...

can you advise me on how I can do that?
Thanks in advance

Subject: helppppp...summation of the corresponding data

From: ImageAnalyst

Date: 18 Dec, 2011 06:02:55

Message: 4 of 10

No, because like I said, I can't figure out how you got the results
matrix B in your example. Do you need to correct it? Or is there
something that you didn't explain quite accurately? Explain why B is
not this:

B=[ 1 1 1 15
      2 1 1 15
      7 1 6 15
     15 1 7 15
      1 3 6 12
      2 3 6 12
      1 4 1 10
      3 4 7 10
     15 4 2 10];
From your written description the above is what it appears to me that
it should look like. Because 15 = 1+1+6+7 (sum of the "1" rows), and
12 = 6+6 (sum of the "3" rows), and 10 = 1+7+2 (sum of the "4" rows).
Why did you not get that? And again, explain how TOL is supposed to
work.

Subject: helppppp...summation of the corresponding data

From: SM

Date: 18 Dec, 2011 09:35:09

Message: 5 of 10

the fact is that...the elements of the column 3 are summed up...if the difference between the elements of the difference of the corresponding values in colum one is Less than TOL...:that means if:
A=[1 1 3 0;....
      2 1 7 0;...
      5 1 6 0];

Assuming TOL=2, then B would be:
 B=[1 1 3 10
      2 1 7 10
      5 1 6 6]
that the part in fact is not working...my code sums up all the values and ignors the setting of the TOL.
How can I include this there?
Thanks again

Subject: helppppp...summation of the corresponding data

From: ImageAnalyst

Date: 18 Dec, 2011 13:58:47

Message: 6 of 10

On Dec 18, 4:35 am, "SM " <khanmor...@gmail.com> wrote:
> the fact is that...the elements of the column 3 are summed up...if the difference between the elements of the difference of the corresponding values in colum one is Less than TOL...:that means if:
> A=[1 1 3 0;....
>       2 1 7 0;...
>       5  1 6 0];
>
> Assuming TOL=2, then B would be:
>  B=[1 1 3 10
>       2 1 7 10
>       5 1 6  6]
> that the part in fact is not working...my code sums up all the values and ignors the setting of the TOL.
> How can I include this there?
> Thanks again
-----------------------------------------------------------------------------------------
OK, column 4 for row #3 did not get set to 10 like the first two
rows. Why not? Tell me what two elements you're subtracting to
determine that the difference is less than 2.
Is it A(3,3) - A(3,1)? So that 6-5 = 1, which is less than 2.
Is it A(3,3) - A(2,3)? So that 6-7 = -1, which is less than 2.
What is it?
And what is the motivation for this? Do you have some plots of
signals/images you'd like to filter? Like it's a moving sum window or
moving max window or something like that?

Subject: helppppp...summation of the corresponding data

From: SM

Date: 18 Dec, 2011 15:14:08

Message: 7 of 10

Actually, that TOL only checks the validity of the A(:,1) i.e.

A(2,1)-A(1,1)=2-1= 1, which is less than TOL=2;
So, A(1,4)=A(1,3)+A(2,3);
and A(2,4)=A(1,3)+A(2,3);

but A(3,1)-A(2,1)=5-2= 3
which is larger than TOL=2,
therefore, the summation will not operate on this one:
then A(3,4) remain as it was before.

the motivation is get the trend per group over the time...
first column represents the time, second column represents the group number, and third column is the value for that group.

I want to calculate trend over time. So, but not every single time. I calculate the trend every 2 time, so I need group the corresponding data for that group, and later, to calculate the trend,(the summation of the values in current time) - (the summation of the values in previous time ).

is it possible to do this trending...I am badly stock....:(...

-----------------------------
ImageAnalyst <imageanalyst@mailinator.com> wrote in message <9493c7d6-bffa-439b-b33e-6f8f44ff2078@b32g2000yqn.googlegroups.com>...
> On Dec 18, 4:35 am, "SM " <khanmor...@gmail.com> wrote:
> > the fact is that...the elements of the column 3 are summed up...if the difference between the elements of the difference of the corresponding values in colum one is Less than TOL...:that means if:
> > A=[1 1 3 0;....
> >       2 1 7 0;...
> >       5  1 6 0];
> >
> > Assuming TOL=2, then B would be:
> >  B=[1 1 3 10
> >       2 1 7 10
> >       5 1 6  6]
> > that the part in fact is not working...my code sums up all the values and ignors the setting of the TOL.
> > How can I include this there?
> > Thanks again
> -----------------------------------------------------------------------------------------
> OK, column 4 for row #3 did not get set to 10 like the first two
> rows. Why not? Tell me what two elements you're subtracting to
> determine that the difference is less than 2.
> Is it A(3,3) - A(3,1)? So that 6-5 = 1, which is less than 2.
> Is it A(3,3) - A(2,3)? So that 6-7 = -1, which is less than 2.
> What is it?
> And what is the motivation for this? Do you have some plots of
> signals/images you'd like to filter? Like it's a moving sum window or
> moving max window or something like that?

Subject: helppppp...summation of the corresponding data

From: SM

Date: 18 Dec, 2011 16:00:10

Message: 8 of 10

Actually, that TOL only checks the validity of the A(:,1) i.e.

A(2,1)-A(1,1)=2-1= 1, which is less than TOL=2;
So, A(1,4)=A(1,3)+A(2,3);
and A(2,4)=A(1,3)+A(2,3);

but A(3,1)-A(2,1)=5-2= 3
which is larger than TOL=2,
therefore, the summation will not operate on this one:
then A(3,4) remain as it was before.

the motivation is get the trend per group over the time...
first column represents the time, second column represents the group number, and third column is the value for that group.

I want to calculate trend over time. So, but not every single time. I calculate the trend every 2 time, so I need group the corresponding data for that group, and later, to calculate the trend,(the summation of the values in current time) - (the summation of the values in previous time ).

is it possible to do this trending...I am badly stock....:(...

-----------------------------
ImageAnalyst <imageanalyst@mailinator.com> wrote in message <9493c7d6-bffa-439b-b33e-6f8f44ff2078@b32g2000yqn.googlegroups.com>...
> On Dec 18, 4:35 am, "SM " <khanmor...@gmail.com> wrote:
> > the fact is that...the elements of the column 3 are summed up...if the difference between the elements of the difference of the corresponding values in colum one is Less than TOL...:that means if:
> > A=[1 1 3 0;....
> >       2 1 7 0;...
> >       5  1 6 0];
> >
> > Assuming TOL=2, then B would be:
> >  B=[1 1 3 10
> >       2 1 7 10
> >       5 1 6  6]
> > that the part in fact is not working...my code sums up all the values and ignors the setting of the TOL.
> > How can I include this there?
> > Thanks again
> -----------------------------------------------------------------------------------------
> OK, column 4 for row #3 did not get set to 10 like the first two
> rows. Why not? Tell me what two elements you're subtracting to
> determine that the difference is less than 2.
> Is it A(3,3) - A(3,1)? So that 6-5 = 1, which is less than 2.
> Is it A(3,3) - A(2,3)? So that 6-7 = -1, which is less than 2.
> What is it?
> And what is the motivation for this? Do you have some plots of
> signals/images you'd like to filter? Like it's a moving sum window or
> moving max window or something like that?

Subject: helppppp...summation of the corresponding data

From: ImageAnalyst

Date: 18 Dec, 2011 17:30:17

Message: 9 of 10

% Get first column
firstCol = A(:, 1);
% Get the difference in the firs column
diffCol1 = diff(firstCol);
% Get a logical where the diff > TOL
rowStaysUnchanged = [0 diffCol1] > TOL;

Do your other stuff to get B, then put the things < tol back to the
original A(, 4) value.

B(rowStaysUnchanged, 4) = A(rowStaysUnchanged, 4);

Try that. I couldn't test it because I'm not on a computer with
MATLAB at the moment.

Subject: helppppp...summation of the corresponding data

From: SM

Date: 18 Dec, 2011 23:00:10

Message: 10 of 10

I tried the code in following way, but I only get the result for the first group, the loop does not iterating...:(...

A=[ 1 1 1 0;...
      2 1 1 0;...
      7 1 6 0;...
     15 1 7 0;...
      1 3 6 0;...
      2 3 6 0;...
      1 4 1 0;...
      3 4 7 0;...
     15 4 2 0];

GroupNumber=unique(A(:,2));
TOL=2;
B=A;

for i=1:length(GroupNumber);
index= A(:,2)==GroupNumber(i);
firstCol = A(index, 1);
diffCol1 = diff(firstCol);
rowStaysUnchanged = [0; diffCol1] > TOL;
B(rowStaysUnchanged, 4) = A(rowStaysUnchanged, 3);
rowchanged=~rowStaysUnchanged;
B(rowchanged, 4) = sum(A(rowchanged, 3));
end

B=[1 1 1 2
     2 1 1 2
     7 1 6 6
   15 1 7 7
     1 3 6 0
     2 3 6 0
     1 4 1 0
     3 4 7 0
   15 4 2 0

You see only it operates for the first group...What if I want to do the same thing for group number 3 and 4...why my loop does not working...:(...???

Thanks a million in advance...
---------------------------

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <0043d807-6187-4ca0-b3bf-6d1049d75467@v29g2000yqv.googlegroups.com>...
> % Get first column
> firstCol = A(:, 1);
> % Get the difference in the firs column
> diffCol1 = diff(firstCol);
> % Get a logical where the diff > TOL
> rowStaysUnchanged = [0 diffCol1] > TOL;
>
> Do your other stuff to get B, then put the things < tol back to the
> original A(, 4) value.
>
> B(rowStaysUnchanged, 4) = A(rowStaysUnchanged, 4);
>
> Try that. I couldn't test it because I'm not on a computer with
> MATLAB at the moment.

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