Changing amount of decimals in between loops
1 次查看(过去 30 天)
显示 更早的评论
So I have a for loop that repeats 3 times, the first time my answer needs to have 3 decimal places but then when it runs the second and third time I need to have 4 decimal places. How do I change the number of decimal places between the three loops
1 个评论
Walter Roberson
2020-7-2
编辑:Walter Roberson
2020-7-3
Places_to_round_to = [3 4 4];
for K = 1 : whatever
calculate something
YourVariable = round(YourVariable, Places_to_round_to(K));
end
回答(1 个)
Les Beckham
2020-7-3
Just index into the vector that you created that specifies the number of places to which you wish to round for that iteration in the loop.
YourVariable = round(YourVariable, Places_to_round_to(K));
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!