MATLAB: Printing table susing fprintf

fprintf

I have the following script; my problem is that I cannot get all the values in A under column A in the frprintf. Any ideas?
A=[1;3;2;8;9]; B=2*pi*A; fprintf('A B\n'); fprintf('======\n'); fprintf('%d %d\n',A,B);

Best Answer

Use:
fprintf('%d %d\n', [A, B].');
Then the elements of A and B appear alternating in the provided array:
C = [A, B].';
C(:)
Note that Matlab addresses the matrix in columnwise order.
With the original command fprintf('%d %d\n',A,B); Matlab uses the format string to print all elements of A at first and then all of B, but not alternating.