Using fprintf with a mixture of numbers and text in a table
조회 수: 6 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
채택된 답변
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
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 Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!