a=[1,2,3;4,5,6] is a 2x3 matrix
1 2 3
4 5 6
Fid=fopen (' d:\chr.txt ', ' wt ') This command usage can be found online, the Help file is also very clear
fprintf (FID, '%8.4f%8.3f%6.2f\n ', a ') output matrix
Fclose (FID) close file
Tell me the meaning of each item in the fprintf command:
FID function handle, which represents the previously opened file
'%8.4f%8.3f%6.2f\n ' output format, specifically as follows:
1,%8.4f means the output format is floating-point number, occupy 8 bits (including decimal point), retain 4 decimal places
2,%8.3f%6.2f with 1
3, \ n means line break
4. Give three different output formats before line break to indicate three data per line (of course, three formats can be the same, except for each line of output three data must be written three times), that is, the newline character before several output format, each line output a few data.
5, but this is not enough, because the output of Shun is based on the matrix single subscript index mode output, that is, if the output matrix if written A, then the output matrix is
1 4 2
5 3 6
6, so need to transpose a, so that the output of the matrix is correct.
Matlab fprintf output matrix