How can I use the tab format specifier and make the elements left justified with DISP function?

22 views (last 30 days)
When I try using the DISP command to produce an output, I am unable to separate the elements by "tab" character and left justify the output. This happens when I run
for i=1:32
disp([num2str(YawAng(i),'%9.2f'),' ',num2str(minMX(i),'%9.1f'),' ',...
num2str(lowerMX(i),'%9.1f'),' ',num2str(meanMX(i),'%9.1f'),' ',...
num2str(upperMX(i),'%9.1f'),' ',num2str(maxMX(i),'%9.1f'),' ',...
num2str(stdMX(i),'%9.3f'),'\t'])
end

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
The SPRINTF command gives a better control over the display format as compared to the DISP command. This example uses the SPRINTF function to print on screen the elements of a matrix 'a' with the elements spaced by "tab" character. The screen output is left justified by setting the '-' flag with the SPRINTF command.
a=[1111.111 22.2222 33.33; 444.4 555.55 66.0];
for i=1:2
y(i,:)=sprintf('%-7.3e \t %-6.4e \t %-5.1e',a(i,1),a(i,2),a(i,3));
end;

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!