how to use a simple statement to describe a repeat format output about the function "fprintf"?
13 次查看(过去 30 天)
显示 更早的评论
For example, fprintf(fid,'%4.2f %4.2f %4.2f %4.2f %4.2f',data) there are 5 '%4.2f', Can a simple statement like the (5'%4.2') to simplify the output format? I have no idea about it and do not find in the documents of matlab.
0 个评论
采纳的回答
Matt Fig
2012-11-17
fprintf(fid,repmat('%4.2f',1,5),data)
3 个评论
Henry Wolkowicz
2025-4-19
编辑:Henry Wolkowicz
2025-4-19
can one complicate things with
C={'%5.2f & '} for latex table purposes? I keep getting 'number' echos if I try this
更多回答(1 个)
Image Analyst
2012-11-17
No need to replicate the format string - it will do that automatically. Try it this way:
fprintf(fid,'%4.2f ', data);
3 个评论
Image Analyst
2012-11-22
Not sure I understand. That will have every 9th element print with a field width of 5 and the 8 numbers in between print with a field width of 4. Also the printout line will have 9 numbers per row whereas your array has 8 numbers per row. Is that what you want, or not? Because that's what you'd be telling it to do.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Standard File Formats 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!