To concatenate two tables in MATLAB that have different sizes, you can use the outerjoin
function from the Statistics and Machine Learning Toolbox. This function allows you to merge two tables based on a key variable, and it replaces the non-matching values with NaN
.
Here's an example of how to concatenate two tables and replace the mismatch with NaN
:
main.m283 chars10 lines
Output:
main.m87 chars5 lines
In this example, table1
and table2
have different sizes but the same number of variables. The outerjoin
function combines the two tables based on the common variables (A
in this case) and includes NaN
for the non-matching values in C
and D
.
Note that you'll need the Statistics and Machine Learning Toolbox to use the outerjoin
function. If you don't have this toolbox, you can alternatively use the join
function, which is built-in but does not handle non-matching values automatically.
gistlibby LogSnag