I have an array matrix, for example A(3,3), I want to make a table with header names like, ['force','mass','acceleration'], the second row contains the units (subheader), ['N','Kg','m/s^2'], and the rest of the table contains the elements of A.
I want to export this table as a (.dat) file, how can I do that in an efficient way (I want to implement it for a large number of matrices)?
This is my code, which I believe it is not professional.
A = [1,2,3;4,5,6];
C(1,:) = {'force','mass','acceleration'};
C(2,:) = {'N','Kg','m/s^2'};
C(3,:) = num2cell(A(1,:));
C(4,:) = num2cell(A(2,:));
T = cell2table(C)
writetable(T,'tabledata.dat')
also this is a new update
A = [1,2,3;4,5,6;7,8,9];
C(1,:) = {'N','Kg','m/s^2'};
C(3:5,:) = num2cell(A(:,:));
T = cell2table(C)
T.Properties.VariableNames = {'force' 'mass' 'acceleration'};
writetable(T,'tabledata.dat','Delimiter','\t')