MATLAB: Help with using fprintf and matrices

fprintfmatrices

Hello!
So I am attempting to list the list the surface area and volume of a sphere when given the radius in matrix form. However I am having trouble with is utilizing the fprintf command correctly to list these values.
format compact
R = [0:.25:3];
SA = 4*pi*(R).^2;
V = (4/3)*pi*(R).^3;
fprintf('\n\n');
disp(' Radius Surface Area Volume');
formatspec = '%9.2f in%10.3f in^2%10.3f in^3 \n';
fprintf(formatspec,R',SA',V')
I am attempting to get the Radius, Surface Area, and Volume to be in their own seperate columns, but the output looks like this.
Radius Surface Area Volume
0.00 in 0.250 in^2 0.500 in^3
0.75 in 1.000 in^2 1.250 in^3
1.50 in 1.750 in^2 2.000 in^3
2.25 in 2.500 in^2 2.750 in^3
3.00 in 0.000 in^2 0.785 in^3
3.14 in 7.069 in^2 12.566 in^3
19.63 in 28.274 in^2 38.485 in^3
50.27 in 63.617 in^2 78.540 in^3
95.03 in 113.097 in^2 0.000 in^3
0.07 in 0.524 in^2 1.767 in^3
4.19 in 8.181 in^2 14.137 in^3
22.45 in 33.510 in^2 47.713 in^3
65.45 in 87.114 in^2 113.097 in^3
If anyone can help seperate them, I'd appreciate it!

Best Answer

It is usually necessary to experiment.
Try this:
fprintf(formatspec,[R',SA',V']')
or equivalently:
fprintf(formatspec,[R; SA; V])
both producing:
Radius Surface Area Volume
0.00 in 0.000 in^2 0.000 in^3
0.25 in 0.785 in^2 0.065 in^3
0.50 in 3.142 in^2 0.524 in^3
0.75 in 7.069 in^2 1.767 in^3
1.00 in 12.566 in^2 4.189 in^3
1.25 in 19.635 in^2 8.181 in^3
1.50 in 28.274 in^2 14.137 in^3
1.75 in 38.485 in^2 22.449 in^3
2.00 in 50.265 in^2 33.510 in^3
2.25 in 63.617 in^2 47.713 in^3
2.50 in 78.540 in^2 65.450 in^3
2.75 in 95.033 in^2 87.114 in^3
3.00 in 113.097 in^2 113.097 in^3
that appears to be what you want.