round off to nearest 5 instead of 10

80 ビュー (過去 30 日間)
Ben
Ben 2014 年 12 月 9 日
コメント済み: John D'Errico 2020 年 10 月 4 日
is that any way to round off to nearest 5 instead of 10? for example, round off 346 to 345; 293 to 295; 296 to 295;
thx for help :p
  3 件のコメント
Aiman Waheed
Aiman Waheed 2020 年 10 月 4 日
How can I get round nearest tenth in Matlab
John D'Errico
John D'Errico 2020 年 10 月 4 日
@Aiman Waheed:
Use round. READ THE HELP FOR ROUND. Unless you have an old release of MATLAB, round has allowed you to round to any number of digits for some years now.
Note that you cannot round to an EXACT decimal, since MATLAB does not store numbers in a decimal form.

サインインしてコメントする。

採用された回答

Adam
Adam 2014 年 12 月 9 日
編集済み: Adam 2014 年 12 月 9 日
round( x / 5 ) * 5;
  2 件のコメント
Ben
Ben 2014 年 12 月 9 日
thanks!!! why i never think in this way!
Adam
Adam 2014 年 12 月 9 日
Well, it isn't always easy. I asked a question on creating a matrix to which the answer provided by Rick Rosson was similarly trivial a few months ago, but only if your thought process takes you in that direction!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by