How to round up to closest 0 or 5 in array?
6 ビュー (過去 30 日間)
古いコメントを表示
Code
utp = [420.680537950975, 412.407955038480, 389.575547217989, 366.089887932711, 363.090652446469, 352.095749639858];
% https://se.mathworks.com/matlabcentral/answers/14495-rounding-elements-in-array-to-nearest-0-25
up = ceil(utp * 2) / 2;
down = floor(utp * 2) / 2;
Expected output
420
410
390
365
365
350
I started to think to make an for-loop for the task but really - it does not feel like MATLAB.
Maybe, there is something built-in.
MATLAB: 2016b OS: Debian 8.5
0 件のコメント
回答 (1 件)
Walter Roberson
2016 年 10 月 25 日
round(utp*5)/5
2 件のコメント
John D'Errico
2016 年 10 月 25 日
編集済み: John D'Errico
2016 年 10 月 25 日
oops. To round to the nearest multiple of 5, I expect you meant to write:
round(utp/5)*5
参考
カテゴリ
Help Center および File Exchange で Startup and Shutdown についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!