delete all the decimal digits that are 0 after the first decimal place
Show older comments
Hi! I need to transform the vector V with only the first decimal. Is there an easy way to do this?
For example I am trying this way but the 9 becomes 9.0:
V = [
6.20000000000000
7.50000000000000
9
10.2000000000000
9.40000000000000];
F = {};
for ii = 1:height(V)
FF = sprintf('%.1f', V(ii));
F = [F,{FF}];
end
1 Comment
Dyuman Joshi
on 10 Sep 2023
Do you want the output to be numeric or string/char?
It would be better if you could specify what the expect output is.
Accepted Answer
More Answers (1)
Here is one slightly different option:
V = [
6.20000000000000
7.50000000000000
9
10.2000000000000
9.40000000000000];
for ii=1:numel(V)
FF{ii} = num2str(round(V(ii), 1), '%.1f');
end
FF
Categories
Find more on Logical 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!