File Exchange

image thumbnail

tableAppend - Easily append selected variables to table

version (1.41 KB) by Germán
Merge tables with mismatching number of variables and fill missing variables with NaN

1 Download

Updated 02 Apr 2014

View License

It usually happens that you want to add rows to a table but you only have part of the original variables. There is currently no way to do this without having to create a table row with the complete list of variables.
tableAppend will concatenate the variables that are present in the original table, and will pad with NaN or 'NA' the missing variables.



var 1var2 var3
---- ---- ----
'a' 45 6
'b' 14 3
'c' 56 5



tbl3 = tableAppend(tbl1, tbl2);


var1 var2 var3
---- ---- ----
'a' 45 6
'b' 14 3
'c' 56 5
'NA' NaN 8
'NA' NaN 2

Cite As

Germán (2021). tableAppend - Easily append selected variables to table (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (1)

Rutger Tromp

Nice tool to have. One remark though: in order to make it function in R2016a I had to change line 37 from

tbl2Cell(:,iVar1) = tbl2{:,var2i};


tbl2Cell(:,iVar1) = num2cell(tbl2{:,var2i});

Please update the function to keep it in line with recent Matlab developments.

Kind regards,

MATLAB Release Compatibility
Created with R2014a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!