MATLAB: Using save() and -ascii format to limit output numbers to 2 decimals

asciiMATLAB

Hello All, I need help with save() command. here is the extract of my code:
save(fullfile(PathName,filename),'x','-ascii');
Where x is a column of 120 values upto 2 decimal points.
Now what I am getting with above code is 4.7300000e+01 which I want to limit to 47.30 only. I know they are one of same but I have another script which reads only 47.30 kind of format. So even though both are same I have to restrict it to 2 decimals only.
So is there any way to do that?

Best Answer

Method one: fprintf:
fnm = fullfile(PathName,filename);
fid = fopen(fnm,'wt');
fprintf(fid,'%.2f\n',x);
fclose(fid);
Method two: dlmwrite:
dlmwrite(fnm,x,'precision','%.2f')
Related Question