Remove trailing zeros
Version 1.1.0 (227 KB) von
Peter Seibold
Format double numbers to n digits and remove all trailing zeros. Processed with regular expression.
Format double numbers to ndd digits and remove all trailing zeros
function output = RemoveTrailingZeros(input,ndd)
INPUTS:
input: n x m double array
ndd: number of decimal digits, whole double, ndd >= 0, optional, default = 2
OUTPUT:
output: n x m cell array
Process time on my PC: 3.5 s for a 1000 x 1000 array (6 ms + 3.5 us per number)
EXAMPLES:
Format with default precision (2 decimal digits) and remove trailing zeros:
output = RemoveTrailingZeros([1.23456, 2.5]);% output: [{'1.23'} {'2.5'}]
Format with 4 decimal digits and remove trailing zeros:
output = RemoveTrailingZeros([1.23456, 2.5],4);% output: [{'1.2346'} {'2.5'}]
Some input/output examples:
Zitieren als
Peter Seibold (2026). Remove trailing zeros (https://de.mathworks.com/matlabcentral/fileexchange/158961-remove-trailing-zeros), MATLAB Central File Exchange. Abgerufen.
Kompatibilität der MATLAB-Version
Erstellt mit
R2020a
Kompatibel mit allen Versionen
Plattform-Kompatibilität
Windows macOS LinuxTags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Live Editor erkunden
Erstellen Sie Skripte mit Code, Ausgabe und formatiertem Text in einem einzigen ausführbaren Dokument.
RemoveTrailingZeros240612
| Version | Veröffentlicht | Versionshinweise | |
|---|---|---|---|
| 1.1.0 | Removed a bug related to Matlab versions older than R2016b |
||
| 1.0.1 | Restriction regarding the MATLAB version dependency removed |
||
| 1.0.0 |
