I made this table and I am having trouble formatting it. I want all the decimals in each column to line up and have each value to 2 decimal plays but because of the negatives and different number of values before the table it screws everything up. Whats a better way to format this? Thanks. P.S. Am I even using meshgrid correctly? It is a homework problem and I need to use meshgrid and vectorized calculations. My values are all right just not sure if making the variables x1, x2, x3 is necessary.
clear
t=0:10;
v=[10, -10, 20];
a=[2, 4, -6];
[V,A,T]=meshgrid(v,a,t);
x=V.*T+0.5.*A.*T.^2;
x1=x(1,1,:);
x2=x(2,2,:);
x3=x(3,3,:);
fprintf('\n');
fprintf('------------------------------------\n');
fprintf(' v = 10 v = -10 v = 20\n');
fprintf('t a = 2 a = 4 a = -6\n');
fprintf('------------------------------------\n');
for k=(1:11),
fprintf('%2d %3.2f %3.2f %3.2f\n', t(k), x1(k), x2(k), x3(k));
end