rounding elements in array to nearest 0.25
古いコメントを表示
i need to round off some numbers to nearest quarter , with an option to round up or round down to nearest quarter
for e.g. For an array for (5,1) with following values
1373.698
1385.024
1394.82
1400.436
1396.532
output for rounding up to closest 0.25 will result in
1373.75
1385.25
1395.00
1400.50
1396.75
output for rounding down to closest 0.25 will be
1373.50
1385.00
1394.75
1400.25
1396.50
I am not sure how to create such a function which gives this output, please help .
1 件のコメント
Tod Wood
2017 年 2 月 4 日
B=[3;4;6;9]*29.17658137; B_round_25=round(4*B)/4;
採用された回答
その他の回答 (2 件)
Walter Roberson
2011 年 8 月 25 日
The previous answers look more complex than needed
%round up
up = ceil(in * 4) / 4;
%round down
down = floor(in * 4) / 4;
Anders Tagmose Lundsfryd
2021 年 3 月 17 日
編集済み: Anders Tagmose Lundsfryd
2021 年 4 月 6 日
If you want to round to the nearest 0.25 both up and down, then do:
%roudn to nearest 0.25
updown = round(in * 4)/4;
1 件のコメント
Matthias Schneider
2023 年 12 月 4 日
works perfect
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!