% Creating Table1
T1=table(['A';'B';'C'],[2;5;6],[3;7;8],[4;8;6],'VariableNames',{'SampleName','P1','P2','P3'})
T1 =
SampleName P1 P2 P3
__________ __ __ __
A 2 3 4
B 5 7 8
C 6 8 6
% Creating Table2
T2=table(['A';'B';'D'],[1;2;5],[3;5;7],'VariableNames',{'SampleName','P4','P5'})
T2 =
SampleName P4 P5
__________ __ __
A 1 3
B 2 5
D 5 7
% Joining the two tables
C=outerjoin(T1,T2,'MergeKeys',1)
C =
SampleName P1 P2 P3 P4 P5
__________ ___ ___ ___ ___ ___
A 2 3 4 1 3
B 5 7 8 2 5
C 6 8 6 NaN NaN
D NaN NaN NaN 5 7
%Replacing NaN values with zeros
for i=2:size(C,2)
mask=isnan(table2array(C(:,i)));
C(mask,i)={0};
end
C =
SampleName P1 P2 P3 P4 P5
__________ __ __ __ __ __
A 2 3 4 1 3
B 5 7 8 2 5
C 6 8 6 0 0
D 0 0 0 5 7