필터 지우기
필터 지우기

Help correlating data using join, innerjoin, outerjoin to compare datasets with common date which is in DD-MMM-YYYY format.

조회 수: 2 (최근 30일)
I have a problem with correlating 2 tables using join, innerjoin, outerjoin to compare datasets with common date which is in DD-MMM-YYYY format. Both tables have dates in the DD-MMM-YYYY format, however MatLab does not recognise these data dates as "common variables." I get the error: "Cannot find a common table variable to use as a key variable."
Example for clarification,
A = [28-Jun-2019, 1; 01-Jul-2019, 2; 02-Jul-2019, 3; 03-Jul-2019, 4];
B = [28-Jun-2019, 23; 03-Jul-2019; 37];
I would like to combine A and B into new matrix, C, relating / correlating the datasets using the date, such that:
C=
28-Jun-2019 1 23
01-Jul-2019 2
02-Jul-2019 3
03-Jul-2019 4 37
Any guidance would be much appreciated!
Thanks,
Dominic
  댓글 수: 1
Guillaume
Guillaume 2019년 7월 5일
편집: Guillaume 2019년 7월 5일
You mention tables and then matrices. They're two completely different things. join only works with tables. If you have tables, what are the variable names of each table?
As you don't use valid matlab syntax in your examples, it's not even clear how your dates are stored. Are they datetime arrays or something else (if so what?)
Any reason you're not using timetables and synchronize?

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

답변 (1개)

Rajani Mishra
Rajani Mishra 2019년 7월 17일
Hi,
I assume you want to combine table ‘A’ and table ‘B’ using a column which is in
DD-MMM-YYYY format in both the tables to create a new table ‘C’.
I think reason behind the error "Cannot find a common table variable to use as a key variable."
is that the date column in table ‘A’ and ‘B’ have different names.
You can use ‘VariableNames’ argument while creating the tables.
T = table(___,'VariableNames,varNames)
Where ‘varNames’ is a cell array of character vectors used to specify names of the variables(columns) of the table
Then you can use ‘outerjoin(A,B)’ to create table C. Refer to this link for more information:

카테고리

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