How to write a matrix into a txt file so that all variables in a columns have exactly the same starting character and length?
1 次查看(过去 30 天)
显示 更早的评论
I am trying to export a matrix into a text file. The text file will later be feed into another program that requires all variables in a specific columns have the same starting location, and the same length.
How should I achieve this? Which Matlab function should I use to export the data?
Thank you.
0 个评论
采纳的回答
Fangjun Jiang
2011-4-21
use sprintf formating, such as
a=rand(5,1);
sprintf('%20.2f\n',a(:));
doc sprintf
It also applies to fprintf.
2 个评论
Walter Roberson
2011-4-21
No, sprintf() and fprintf() will repeat the format as often as needed to write out all the data.
更多回答(2 个)
Fangjun Jiang
2011-4-25
What do you mean? What exact format do you want to achieve? Please read through the document of sprintf formatting. I think it should be able to cover most if not all format.
Is this what you need?
sprintf('%010.2f\n',45,-45,26.7,126.8)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Data Preparation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!