![]() |
matlab的fortran格式等效项
什么是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输出格式化的东西)。 [I]编辑肯尼:[/I]对于上述a的值,它将给出(在新行中): Speed, resistance, power 10.00 20.00 200.00 [B]回答:[/B] 我使用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 [B]编辑[/B] 假设数组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') [url=https://stackoverflow.com/questions/2751453]更多&回答...[/url] |
所有时间均为北京时间。现在的时间是 03:01。 |
Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.