Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

matlab code

Status
Not open for further replies.

Willy26

Civil/Environmental
May 6, 2020
1
0
0
IT
Hi and thank you for considering this post.
I have 2 time series (MID1 and MID2). They have a table format with 2 rows each. The first row is the date and the second row is a value. Both time series don't have continuouse dates.

For example
MID1:
01.02.2010 - 34
04.02.2010 - 37
07.02.2010 - 60
08.02.2010 - 61

MID2:
31.01.2010 - 20
02.02.2010 - 30
04.02.2010 - 32
06.02.2010 - 41
07.02.2010 - 40

I want to compare the data row. If the time series of MID1 and MID2 have the same date (in the example the 04.02.2010 and 07.02.2010) the values in the value rows should be summarized. If the comparison don't find the same date, it should be considered just the value of MID1 or MID2.
in the case of the example like this:

total:
31.01.2010 - 20
01.02.2010 - 34
02.02.2010 - 30
04.02.2010 - 37 + 32 = 69
06.02.2010 - 41
07.02.2010 - 60 + 40 = 100
08.02.2010 - 61

I was thinking it could work with a double loop like this:

MID1 with 1st row (date) and 2nd row (value)
MID2 with 1st row (date) and 2nd row (value)

-------------
total=zeros(2709,1)
for i=1:2709
for ii=1:2709
if MID1.date(i)==MID2.date(ii)
total(i)= MID1.value+MID2.value
elseif MID1.date(i)~=MID2.date(ii)
total(i)=MID1.value
else MID2.date(i)~=MID1.date(ii)
total(i)=MID2.value

end
end
end
-------------

As I'm super weak in programming, it didn't work out well. Could you help me in solving the problem?

thanks a lot!
 
Replies continue below

Recommended for you

Status
Not open for further replies.
Back
Top