[英]Produce table with text and number with fprintf in Matlab
I need to produce a table whose first 2 columns have text, and the remaining 2 have numbers. 我需要产生一个表,其前2列具有文本,其余2列具有数字。 Something like this:
像这样:
| Ford | Mustang | 1975 | 35 |
| Chev | Camaro | 1976 | 38 |
I have the string in a cell, and the numeric variables in a matrix. 我在单元格中有字符串,在矩阵中有数字变量。 I've tried with fprintf but can't make it work.
我已经尝试过使用fprintf,但是无法使其正常工作。 I have no problems doing it in xlswrite, but I don't want to go that way.
我在xlswrite中执行此操作没有问题,但我不想那样做。 Any ideas please?
有什么想法吗?
Thanks! 谢谢!
You could use fprintf
in a loop like this: 您可以在如下循环中使用
fprintf
:
fprintf(1, '| %8s | %8s | %4d | %2d |\n', ...
company{i}, model{i}, year(i), otherNumber(i));
to write to stdout. 写到stdout。 You can also modify the
%#s
if you want different spacing in your table, or provide a different file descriptor to the first argument. 如果要在表中使用不同的间距,也可以修改
%#s
,或者为第一个参数提供不同的文件描述符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.