How to write specified datas formatted in a text file ?
조회 수: 1 (최근 30일)
이전 댓글 표시
Dear users, I have a 3200x9 matrix and there are different types of number forms inside of it. Some of rows are given below.
Fe 26 4.96742E+006 6.7785E+008 -3.0933E+007 -5.291E+007 0.0062407 0.0004310 0.0002620
I want to rewrite these datas into a text file in formatted form such that:
|.|.|.|.|.| |.|.| *|*|*|*|*|*|*|*|*|*|*|
|F|e| | | | |2|6| |4|.|9|6|7|4|2|E|6| | |6|.|7|7|8|5|E|8| |-|3|.|0|9|3|3|E|7|
5 digit 3 digit 10 digit 10 digit 10 digit
\ 1st data / \2nd data/ \3rd data/ \4th data/ \5th data/
First and second columns must be written in 5 and in 3 digits, and others must be written in 10 digits that is 10 digits should be between end-to-end that is included '-' sign and roundeds etc if necessary. I used the following commands but I couldn't be able to do that:
l=size(COLLISION); fid=fopen('DATA.txt','wt') for i=1:l(:,1); fprintf(fid,'Fe %d %7.5E %7.4E %7.4E %7.3E %.7f %.7f %.7f \n',COLLISION(i,2),COLLISION(i,3),COLLISION(i,4),COLLISION(i,5),COLLISION(i,6),COLLISION(i,7),COLLISION(i,8),COLLISION(i,9)); end fclose(fid)
which the COLLISION is the name of matrix.
Attached file is the result of above commands. Thank you
댓글 수: 1
Jan
2013년 9월 19일
You can write COLLISION(i, 2:9).
What happens when you run this code? "I couldn't be able to do that" does not explain the occurring problems, but this is required to solve them.
답변 (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!