-
matlab 不保存為科學計數法 http://blog.sciencenet.cn/blog-472136-402727.html
經常在表示matlab值時,它總會把一些小於1的大於1000的數使用科學計數法表示。這有時讓人看了很不爽,每次把數據寫到文本文件中也是很惡。
所以每次查來查去,這次解決是這樣解決的。
1)、前面設置format g;
2)、使用fprintf設置格式為%g。
- matlab專區--------------matlab里面如何保留小數特定位數 http://blog.csdn.net/yf210yf/article/details/7235907
二、在小數點后某一位四舍五入,即保留幾位小數,也經常用到。
1.數值型 roundn—任意位位置四舍五入
>>a=123.4567890;
>>a=roundn(a,-4)
a = 123.4568
其中roundn函數功能如下:
y = ROUNDN(x) rounds the input data x to the nearest hundredth. %不指定n,精確到百分位
y = ROUNDN(x,n) rounds the input data x at the specified power %精確到小數點后指定位數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