MATLAB: What is the best way to concatenate arrays of different types (matrices and cells of strings or numbers) into a table to be saved in txt file (for Matlab R2011a)

concatenate arrays

Example:
title = ['a', 'b', 'c'];
N = 3;
a = [zeros(N,1), ones(N,1)];
b = {repmat('no',N,1), repmat('yes',N,1)};
c = {[]; 1; [1,2]}
table = {title; a, b, c}

Best Answer

Under simple conditions, writetable just does what you want:
>> N = 3;
>> a = [zeros(N,1) ones(N,1)];
>> b = [repmat({'no'},N,1) repmat({'yes'},N,1)]; % slightly different than yours
>> c = {[]; 1; [1,2]};
>> t = table(a, b, c)
t =
a b c
______ _____________ ____________
0 1 'no' 'yes' []
0 1 'no' 'yes' [ 1]
0 1 'no' 'yes' [1x2 double]
>> writetable(t,'t.dat')
>> type t.dat
a_1,a_2,b_1,b_2,c_1,c_2
0,1,no,yes,,
0,1,no,yes,1,
0,1,no,yes,1,2