我使用1 FILEID写入命令窗口,我把一个换行符到底是因为它的漂亮,但这应该复制你想要什么
a = [10,20,200;20,30,300];
fprintf(1,'Speed, resistance, power%8.2f%8.2f%8.2f\n',a')
Speed, resistance, power 10.00 20.00 200.00
Speed, resistance, power 20.00 30.00 300.00
编辑
假设一个未知尺寸的数组a
。进一步假设我们要fprint它逐行
a = [10,20,200;20,30,300];
%# find number of columns
nCols = size(a,2);
%# create format string for fprintf. Use repmat to replicate the %8.2f's
fmtString = ['Speed, resistance, power',repmat('%8.2f',1,nCols),'\n'];
%# print
fprintf(1,fmtString,a')
Speed, resistance, power 10.00 20.00 200.00
Speed, resistance, power 20.00 30.00 300.00
注意:这将打印在同一线路上的其他后一(感谢,@JS)的所有行。
fprintf('Speed, resistance,power')
fprintf('%8.2f',a')
fprintf('\n')
预期输出是什么?所以那些不了解FORTRAN的人也可以提供帮助。 – kennytm 2010-05-01 21:04:01
@ Kenny - 上面给出的。此外,fortran不再是一个缩写(过去30年给予或采取:) – Rook 2010-05-01 21:24:46