How to write specified datas formatted in a text file ?

1 view (last 30 days)
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 Comment
Jan
Jan on 19 Sep 2013
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.

Sign in to comment.

Answers (0)

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!