Bjorn, you can create a table with three variables, full of NaNs, and then just assign the variables you have read in from each csv. Something like this:
Create an example of a table that might have been read in using readtable:
>> t2 = array2table(randn(5,2),'VariableNames',{'height' 'color'})
t2 =
height color
________ _______
-0.20497 0.6715
-0.12414 -1.2075
1.4897 0.71724
1.409 1.6302
1.4172 0.48889
Preallocate a table of missing values, with the right size:
>> t1 = array2table(nan(height(t2),3),'VariableNames',{'height' 'size' 'color'})
t1 =
height size color
______ ____ _____
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
NaN NaN NaN
Move the data that was read in:
>> t1(:,t2.Properties.VariableNames) = t2
t1 =
height size color
________ ____ _______
-0.20497 NaN 0.6715
-0.12414 NaN -1.2075
1.4897 NaN 0.71724
1.409 NaN 1.6302
1.4172 NaN 0.48889
Do that three times, and the three results can be vertically concatenated, Another possibility:
>> t2 = array2table(randn(5,2),'VariableNames',{'height' 'color'})
t2 =
height color
________ _______
1.0347 0.8884
0.72689 -1.1471
-0.30344 -1.0689
0.29387 -0.8095
-0.78728 -2.9443
>> t2{:,setdiff({'height' 'size' 'color'},t2.Properties.VariableNames)} = NaN
t2 =
height color size
________ ________ ____
1.4384 -0.10224 NaN
0.32519 -0.24145 NaN
-0.75493 0.31921 NaN
1.3703 0.31286 NaN
-1.7115 -0.86488 NaN
Best Answer