Changing amount of decimals in between loops

조회 수: 2 (최근 30일)
Caroline Prekker
Caroline Prekker 2020년 7월 2일
편집: Walter Roberson 2020년 7월 3일
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
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
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));

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by