Remove extra zeros from parameters in the workspace
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (2)
Diwakar Diwakar
am 11 Jun. 2023
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
am 11 Jun. 2023
Without using fprintf(), you can get rid of some of them by putting this in your script at the top.
format short g
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!