I am new to Matlab. Is there a way to use printmat
to print 2 words heading?
Example result as followed:
Title One Title Two
According to Matlabs help, printmat
will not provide what you are seeking. You can use sprintf
instead.
a = [ 11 22 33; 22 33 44];
s = {'Title One' 'Title Two' 'Title Three'};
s1 = sprintf('%12s\t%12s\t%12s\t\n', s{:});
s2 = sprintf('%12d\t%12d\t%12d\n', a);
horzcat(s1,s2)
This results in
ans =
Title One Title Two Title Three
11 22 22
33 33 44
~edit~
If the use of printmat
is preferable (e.g., because it is more flexible) you can work around by using evalc
and strrep
. The trick here is to replace the spaces with other symbols (e.g. question marks) in the call to printmat
, store the output in a string via evalc
, and then use strrep
to replace the question marks by spaces. As a nice byproduct, you get the table as a string...
a = [ 11 22 33; 22 33 44];
x = evalc('printmat(matA, '''' , ''a b c'' , ''Title?One Title?Two Title?Three'')');
s = strrep(x, '?', ' ')
This results in
s =
Title One Title Two Title Three
a 11.00000 22.00000 33.00000
b 22.00000 33.00000 44.00000
However, the combination of printmat and evalc causes a lot of apostrophes...