MATLAB: How to format data in a table

formattable

I want to print the data in the following code in a table instead of in a column, i.e., I want the headers in the first row and the data in each column under it.
Thanks,
filename = 'E:\My Documents\Maheteme\Test Data\myfile02.txt';
delimiterIn = ' ';
headerlinesIn = 1;
A = importdata(filename,delimiterIn,headerlinesIn);
for k = [1, 2, 3, 4, 5, 6, 7, 8, 9]
disp(A.colheaders{1, k})
disp(A.data(:, k))
disp(' ')
end

Best Answer

L=max(cellfun(@length,A.colheaders)); % longest header length for width
N=size(A.data,2); % number colums
fmt1=[repmat(num2str(L+2,'%%%ds'),1,N) '\n']% format header row based on width
fmt2=[repmat(num2str(L+2,'%%%d.2f'),1,N) '\n']% format data rows based on width
fprintf(A.colheaders{1,:}) % and print header row
fprintf(A.data.') % follow with data (@)
(@) Note the transpose to print in row-major order since Matlab internal storage is column-major. VERY important! :)