poster
2019-12-10, 20:41
什么是matlab的等价于
write(1,'("Speed, resistance, power",3f8.2)')(a(i),i=1,3) 我试过了
a = [10. 20. 200.] fprintf(unit1,'a = 3%8.1e',a) 但我仍然遇到麻烦(整个matlab输出格式化的东西)。
编辑肯尼:对于上述a的值,它将给出(在新行中):
Speed, resistance, power 10.00 20.00 200.00
回答:
我使用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的维数未知。进一步假设我们要逐行打印
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')
更多&回答... (https://stackoverflow.com/questions/2751453)
write(1,'("Speed, resistance, power",3f8.2)')(a(i),i=1,3) 我试过了
a = [10. 20. 200.] fprintf(unit1,'a = 3%8.1e',a) 但我仍然遇到麻烦(整个matlab输出格式化的东西)。
编辑肯尼:对于上述a的值,它将给出(在新行中):
Speed, resistance, power 10.00 20.00 200.00
回答:
我使用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的维数未知。进一步假设我们要逐行打印
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')
更多&回答... (https://stackoverflow.com/questions/2751453)