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

1 view (last 30 days)
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 Comment
Guillaume
Guillaume on 5 Jul 2019
Edited: Guillaume on 5 Jul 2019
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?

Sign in to comment.

Answers (1)

Rajani Mishra
Rajani Mishra on 17 Jul 2019
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:

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!