Trying to merge two tables, using time stamps as keys in outerjoin(), getting 'incorrect data type or missing argument' error.
2 次查看(过去 30 天)
显示 更早的评论
Hi!
I have two tables, each with two rows. One is 'raw', and has each possible time stamp and corresponding data. The other is 'valid', and only has time stamps corresponding to valid data. I want to have a third table, that contains all time stamps but NaNs where there isn't both raw and valid data.
So, for example, these would go into outerjoin()
valid = 't_ms' 'val_dat'
[ 1 55
2 50
4 52 ]
raw = [ 1 49
2 37
3 51
4 52 ]
And I'd get a table that's the length of 'raw', and 'valid' containing NaNs. Instead, I get the error:
'Check for incorrect argument data type or missing argument in call to outerjoin.'
I've quadruple checked that I'm inputting tables, and the key variables have the exact same name, and I've tried pretty much every optional argument into outerjoin() I can, no dice.
Any help would be much appreciated, embarrassingly enough I'm stumped!
Thanks
0 个评论
回答(2 个)
Xiaotao
2024-5-22
valid = table([1;2;4],[55 50 52]', 'VariableNames',{'t_ms','val_dat'});
raw = table([1;2;3;4],[49 37 51 52]', 'VariableNames',{'t_ms','raw_dat'});
third = outerjoin(valid, raw,'MergeKeys',true)
0 个评论
Abhas
2024-5-22
Hi Tyler,
MATLAB's "outerjoin" function can be used with "MergeKeys" arguments to fill the missing values with NaNs where there is no match.
Here's the MATLAB code to perform the required steps:
% Define the 'valid' table
valid = table([1; 2; 4], [55; 50; 52], 'VariableNames', {'t_ms', 'val_dat'});
% Define the 'raw' table
raw = table([1; 2; 3; 4], [49; 37; 51; 52], 'VariableNames', {'t_ms', 'raw_dat'});
% Perform the outer join
result = outerjoin(raw, valid, 'Keys', 't_ms', 'MergeKeys', true)
The "result" variable stores the "outerjoin" of the two tables.
You may refer to the following documentation link to have a better understanding on joins:
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!