Appending trailing zeros to integers in a vector
Show older comments
Let's assume I have the following vector:
x = [2, 13, 901, 5, 18, 7, 112, 5931];
And I created a function that first counts the digits using numel function, determines the maximum number of digits (4 digits in this example), then tried to append zeros to the right of each number corresponding to the relation (difference) between the max and the current number of digits, resulting in the following:
x = [2000, 1300, 9010, 5000, 1800, 7000, 1120, 5931];
I couldn't find out a straightforward way to do it.
2 Comments
Matt J
on 13 Sep 2018
Why would you want to do such a thing?
Maamoun Ahmed
on 13 Sep 2018
Accepted Answer
More Answers (0)
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!