【发布时间】:2017-10-27 00:12:34
【问题描述】:
早上好,
我确定有一个内置函数,但我找不到它。我想为发送到 MATLAB 中的文本文档的信息创建静态定位。例如:
height weight age favorite number
------------------------------------------------------------
60 140 24 9
30 45 3 10000000
48 100 9 19
9 7 1 1
目前,我只是使用填充空格进行 fprint 调用以使其对齐,但问题出现在具有不同长度数字会导致对齐关闭的情况下,如下所示:
height weight age favorite number
------------------------------------------------------------
60 140 24 9
30 45 3 10000000
48 100 9 19
1 7 1 1
提前致谢。
这是一个示例脚本,可以说明我的意思:
fid1 = fopen('stackoverflowtest', 'w');
if fid1 < 3,
error('ERROR');
end;
fprintf(fid1, 'height weight age favorite number \n');
fprintf(fid1, '------------------------------------------------------------ \n');
height = 0;
weight = 10;
age = 100;
number = 3;
for i = 1:100
fprintf(fid1, "%d ', height);
fprintf(fid1, "%d ', weight);
fprintf(fid1, "%d ', age);
fprintf(fid1, "%d \n", number);
height = height + 3;
weight = weight + 6;
age = age - 1;
number = number + 23;
end
【问题讨论】:
-
您能否向我们展示您的代码 sn-p,以便我们知道您在使用什么?
-
我添加了一个示例脚本,与我的原始示例保持相同的样式,因为我无法提供确切的代码,但概念是相同的
标签: matlab alignment printf spacing