Add variables from one timetable to another

조회 수: 6 (최근 30일)
Eric Escoto
Eric Escoto 2021년 11월 24일
댓글: Peter Perkins 2021년 11월 26일
Having a bit of trouble with this...
I've got two timetables. Let's call them TT1 and TT2.
One table (TT1) has 11 variables. Another table (TT2) has 1035 variables. They are the same length.
I would like to take variables 12:1035 and move them to the right of the last variable in TT1.
What is the best approach?
  댓글 수: 3
Eric Escoto
Eric Escoto 2021년 11월 24일
I can't see how the synchronize function would work for me.
If I try a code like such:
TT_test = timetable(tmin, TT2{:, [12:1035]}); % Pull columns of interest from TT2 and use tmin as the datetime vector.
Then I wind up with only one variable and not the 1024 variables I want.
Eric Escoto
Eric Escoto 2021년 11월 24일
편집: Eric Escoto 2021년 11월 24일
What I'm trying to show is my indexing isnt correct and I'm not pulling each variable seperately. The result of this syntax is that there is only a single 'var1' with 1024 collumns instead of 1024 vars.

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

답변 (2개)

LeoAiE
LeoAiE 2021년 11월 24일
편집: LeoAiE 2021년 11월 24일
Hi,
I think you could easily achieve that using outerjoin function. First, extract your data from TT2 and give it a name such as NewTable = TT2(12:1035). Then, use outerjoin function to merge them
FinalTable = outerjoin(TT1,NewTable).
Please see the documentation of this function and how to use it examples https://www.mathworks.com/help/matlab/ref/outerjoin.html
And if you find this helpful, make sure to accept the solution!
Thanks

Peter Perkins
Peter Perkins 2021년 11월 24일
Eric, I think all you need is
>> T1 = array2table(rand(5,3),"VariableNames",["A" "B" "C"]);
>> T2 = array2table(rand(5,3),"VariableNames",["X" "Y" "Z"]);
>> T12 = [T1 T2(:,["Y" "Z"])]
T12 =
5×5 table
A B C Y Z
_______ _______ _______ _______ _______
0.48976 0.27603 0.49836 0.95929 0.84072
0.44559 0.6797 0.95974 0.54722 0.25428
0.64631 0.6551 0.34039 0.13862 0.81428
0.70936 0.16261 0.58527 0.14929 0.24352
0.75469 0.119 0.22381 0.25751 0.92926
You will need to make sure you don't have variable name conflicts.
The join functions are sort of a horz cat when you want to match up rows based on their values, not their positions. synchronize is sort of a horz cat whn you want to match up rows (of timetables) based on their times.
  댓글 수: 3
Eric Escoto
Eric Escoto 2021년 11월 24일
Plus, I know I've done this before and am scouring some old scripts but am at the point of just seeing gibbersish in my code. Long week.
Peter Perkins
Peter Perkins 2021년 11월 26일
T12 = [T1 T2(:,12:1035)]?

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

카테고리

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

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by