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

2 ビュー (過去 30 日間)
Bob
Bob 2014 年 12 月 15 日
コメント済み: Image Analyst 2014 年 12 月 15 日
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?

採用された回答

Image Analyst
Image Analyst 2014 年 12 月 15 日
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
  1 件のコメント
Image Analyst
Image Analyst 2014 年 12 月 15 日
If you want a variable of type "table", if you have release R2013b or later, you can do this:
t = table(A, B)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Files についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by