How can I fix the alignment

6 views (last 30 days)
Cristian
Cristian on 20 Apr 2013
The first 10 answers are vertically aligned in a way and the remaining values in another way. How can i fix that?
Here is the program:
nn=length(0:10:720);
P=zeros(nn,1);
V=zeros(nn,1);
x=zeros(nn,1);
alfa_cont=zeros(nn,1);
for alfa=0:10:720
cont=alfa/10+1;
cos_alfa=cosd(alfa);
alfa_cont(cont)=alfa;
x(cont)=76.8*((1-cos_alfa)/2+0.28/4-(0.28/4)*cos_alfa^2);
if (alfa<=180)
P(cont)=0.9;
elseif (alfa<=360)
P(cont)=320.612/((x(cont)+8.93023)^1.32);
elseif (alfa<=540)
P(cont)=1119.9/((x(cont)+8.93023)^1.24);
else
P(cont)=1.1;
end
V(cont)= 0.0448882+x(cont)*pi*(80^2)/4*(10^(-6));
end
figure(1)
plot(V,P,'-r'),title('Diagram P-V'),xlabel('Volume [l]'),ylabel('Pressure [bar]'),grid;
fprintf('\n')
fprintf('alfa\t\tx[mm]\t\tP[bar]\t\tV[l]\n')
fprintf('%-6.4f\t\t%-6.4f\t\t%-6.4f\t\t%-6.4f\n',[alfa_cont x P V]')

Accepted Answer

per isakson
per isakson on 20 Apr 2013
Edited: per isakson on 20 Apr 2013
This does it
fprintf('%8s\t\t%8s\t\t%8s\t\t%8s\n', 'alfa', 'x[mm]', 'P[bar]', 'V[l]' )
fprintf('%8.4f\t\t%8.4f\t\t%8.4f\t\t%8.4f\n',[alfa_cont, x, P, V]')
alfa x[mm] P[bar] V[l]
0.0000 0.0000 0.9000 0.0449
10.0000 0.7455 0.9000 0.0486
20.0000 2.9447 0.9000 0.0597
....
100.0000 50.2820 0.9000 0.2976
110.0000 56.2807 0.9000 0.3278
120.0000 61.6320 0.9000 0.3547
Mixing tabs a spaces is not robust. Depends on the settings of the tabs-positions.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!