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

조회 수: 70 (최근 30일)
adi kul
adi kul 2017년 6월 7일
답변: Do Hieu Trinh 2021년 4월 15일
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?

채택된 답변

Stephen23
Stephen23 2017년 6월 7일
편집: Stephen23 2017년 6월 7일
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')
  댓글 수: 6
adi kul
adi kul 2017년 6월 7일
Please check this question:
https://in.mathworks.com/matlabcentral/answers/343722-how-to-change-default-message-box-when-using-xlsread-filename-1
Jabbar moosavi
Jabbar moosavi 2020년 2월 7일
편집: Jabbar moosavi 2020년 2월 7일
I've same question ,the reference data has 3 columns " x,y and pixel values" but this code save the data under "x".I want all the values in the same columns .
so how can I do that ?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Do Hieu Trinh
Do Hieu Trinh 2021년 4월 15일
Dear Stephen,
Do you know a trick which works for saving data into .m file using matlab.io.saveVariablesToScript?
Best regards,
Do Hieu.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by