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

1 回表示 (過去 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 Center および File ExchangeTables についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by