Clear Filters
Clear Filters

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

1 view (last 30 days)
I have the following 2 arrays.
A=[1; 2; 3; 4];
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?

Accepted Answer

Image Analyst
Image Analyst on 15 Dec 2014
Try this:
A=[1; 2; 3; 4];
fprintf('A B\n');
for row = 1 : length(A)
fprintf('%d %s\n', A(row), B{row});
To get this in the command window:
1 green
2 blue
3 black
4 yellow
  1 Comment
Image Analyst
Image Analyst on 15 Dec 2014
If you want a variable of type "table", if you have release R2013b or later, you can do this:
t = table(A, B)

Sign in to comment.

More Answers (0)


Find more on Tables 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!