MATLAB Specifies that the decimal point retains a 4-bit and non-scientific notation format for storing txt

Source: Internet
Author: User
Tags rounds

    • MATLAB is not saved as scientific counting method http://blog.sciencenet.cn/blog-472136-402727.html

Often in the expression of MATLAB value, it always put some less than 1 of the number greater than 1000 using scientific notation. This sometimes makes people uncomfortable, and it's bad to write data to a text file every time.

So every time I check to find out, this solution is the solution.

1), before setting format G;

2), use fprintf format to%g.

    • matlab area--------------matlab How to preserve the decimal number of specific digits http://blog.csdn.net/yf210yf/article/details/7235907

Second, after the decimal point a rounding, that is, to retain a few decimals, also often used.

1. Numerical type roundn-arbitrary bit position rounding

>>a=123.4567890;

>>A=ROUNDN (a,-4)

A = 123.4568

where the ROUNDN function functions as follows:

y = Roundn (x) rounds the input data x to the nearest hundredth. % does not specify N, accurate to percentile

y = Roundn (x,n) rounds the input data x at the specified power% the specified number of digits after the decimal point n

Format G;A=ROUNDN (a,-4); B=roundn (b,-4); fid = fopen (' a.txt ', ' wt '); Fid2=fopen (' B.txt ', ' wt '); for i=1:m for    J=1:n        fprintf (FID, '%g ', A (i,j));        fprintf (FID, '%c ', ', ');                          fprintf (Fid2, '%g ', B (i,j));        fprintf (Fid2, '%c ', ', ');            End        fprintf (FID, '%c\n ', ');         fprintf (Fid2, '%c\n ', '); End

  

MATLAB Specifies that the decimal point retains a 4-bit and non-scientific notation format for storing txt

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.