MATLAB: Using fprintf with a mixture of numbers and text in a table

fprintfnumberstabletext;

I have the following 2 arrays.
A=[1; 2; 3; 4];
B=['green';'blue';'black';'yellow];
I want to use fprintf to to have A and B as the headings of the table, where column A has [1; 2; 3; 4] and column B has ['green';'blue';'black';'yellow]
How can I do this?

Best Answer

Try this:
clc;
A=[1; 2; 3; 4];
B={'green';'blue';'black';'yellow'};
fprintf('A B\n');
for row = 1 : length(A)
fprintf('%d %s\n', A(row), B{row});
end
To get this in the command window:
A B
1 green
2 blue
3 black
4 yellow