rounding elements in matrix if > or < to 0.75
4 ビュー (過去 30 日間)
古いコメントを表示
example:
3.32==> .032 is < 0.75 ===> 3
0.78===>0.78 is >0.75==> 1
1 件のコメント
回答 (2 件)
Cris LaPierre
2023 年 7 月 17 日
編集済み: Cris LaPierre
2023 年 7 月 17 日
Currently, round uses 0.5 as the threshold. The quickest solution would be to modify your data by subtracting 0.25 to artificially move the threshold. Now, 0.75 become 0.5 and is still rounded up. 1.74 becomes 1.49, and is rounded down. In both cases, you end up with the value you want.
x = [3.32;0.78];
round(x-0.25)
5 件のコメント
Cris LaPierre
2023 年 7 月 17 日
You can determine if it works just by testing it. Do you get the expected results?
Swapnil Tatiya
2023 年 7 月 18 日
you could use this as another way to round your numbers according to what you desire by doing the following
x=[0.33 0.45 1.56 1.77];
x=floor(x+0.25)
Hope this helps!
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で NaNs についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!