Add newer data to older data without repetition

조회 수: 1 (최근 30일)
Martin
Martin 2018년 2월 17일
답변: Peter Perkins 2018년 2월 17일
Imagine 2 two datasets where column 1 is a timestamp, column 2 is data (can be more columns).
Yesterday i had this:
A = [ 1 2 3 4 5 6 7 ; 435 124 525 342 532 533 213 ]'
Today I get this (Rows each day can vary):
B = [ 5 6 7 8 9 10 ; 532 533 213 988 999 777 ]'
So 5:7 (timestamp) overlaps. Any idea how I can end up connecting those time stamps so I can get this:
C= [ 1 2 3 4 5 6 7 8 9 10 ; 435 124 525 342 532 533 213 988 999 777]'
I want to return all the data in A and B without repeating the data common to both A and B (not just simple concatinating)
Thanks in advance

채택된 답변

Guillaume
Guillaume 2018년 2월 17일
편집: Guillaume 2018년 2월 17일
C = union(A, B, 'rows');
Note that your example is neither a timeseries nor a table. Be careful with the terms you use to avoid confusion.
  댓글 수: 3
Guillaume
Guillaume 2018년 2월 17일
No, you were perfectly clear. My brain wasn't engaged properly. I meant to use union instead of intersect.
Fixed now.
Martin
Martin 2018년 2월 17일
Thanks for union, works

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Peter Perkins
Peter Perkins 2018년 2월 17일
If you are using R2016b or later, you may find that using timetables is convenient. For example, union works the same way as what Guillaume showed ...
>> A = timetable(seconds([1 2 3 4 5 6 7]'), [435 124 525 342 532 533 213]')
A =
7×1 timetable
Time Var1
_____ ____
1 sec 435
2 sec 124
3 sec 525
4 sec 342
5 sec 532
6 sec 533
7 sec 213
>> B = timetable(seconds([5 6 7 8 9 10]'),[532 533 213 988 999 777]')
B =
6×1 timetable
Time Var1
______ ____
5 sec 532
6 sec 533
7 sec 213
8 sec 988
9 sec 999
10 sec 777
>> union(A,B)
ans =
10×1 timetable
Time Var1
______ ____
1 sec 435
2 sec 124
3 sec 525
4 sec 342
5 sec 532
6 sec 533
7 sec 213
8 sec 988
9 sec 999
10 sec 777
but timetables also bring along a lot of other functionality around "combining data".

카테고리

Help CenterFile Exchange에서 Tables에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by