Matlab fprintf output matrix

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.