MATLAB: Issues with function Join

join merge matrix datasetMATLAB

Hello everybody,
I'm trying to merge two datasets. One calculated, and one retrieved from data, given by:
A=dataset(Output(:,2),Output(:,1),'VarNames',{'x' 'v'});
B=dataset(datarest(:,x),datarest(:,v),'VarNames',{'x' 'v'});
which results in something in the form of:
A = x v
1 5
4 8
B = x v
2 6
3 7
In this, I want to use the x as keys, and merge it to get a dataset, which states v for every x. For this i'm using
C=join(A,B,'key','x','Type','outer','MergeKeys',true);
And the result is
C = x vleft vright
1 5 NaN
2 NaN 6
3 NaN 7
4 8 NaN
Where I want it to be:
C = x v
1 5
2 6
3 7
4 8
I guess it is possible to filter out the NaN's after the join, but as running time is an issue, i'm wondering if there is a way to do specify it within the join command immediately? I hope the issue is clear, and you can help me out.
Thanks in advance!

Best Answer

Try
C=join(A,B,'key',{'x','v'},'Type','outer','MergeKeys',true);