Remove extra zeros from parameters in the workspace
조회 수: 7 (최근 30일)
이전 댓글 표시
Even if my parameters in the command window are displayed with the short format, which I have set from the preferences, when I copy-paste parameters from the workspace they are not in short format. For example, if I have X = 17.2 in the command window, when I copy-paste from the workspace I have 17.2000000000000. I want to eliminate the extra zeros, is there a way to do it?
Thanks
댓글 수: 0
답변 (2개)
Diwakar Diwakar
2023년 6월 11일
You can use the sprintf function or the num2str function to achieve this.
Example
X = 17.2;
formattedX = sprintf('%.1f', X);
disp(formattedX);
Image Analyst
2023년 6월 11일
Without using fprintf(), you can get rid of some of them by putting this in your script at the top.
format short g
참고 항목
카테고리
Help Center 및 File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!