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!