Round towards target matrix

6 ビュー (過去 30 日間)
Reik
Reik 2012 年 3 月 7 日
Hi @ all :)
I have a small problem with rounding values of a base matrix towards the values of a target matrix. The matrices looks like this:
Base matrix:
# 1.12
# 1.16
# 2.0
# 1.78
# 2.3
# 3.1
# 3.67
# 1.1
# 0.3
Target matrix:
# 0
# 0.3
# 0.8
# 1
# 1.5
# 2.4
# 2.5
# 3.1
# 3.3
# 4
Now I want to round the values of the base matrix to the values of the target matrix, resulting to this "round values":
# 1.12 -> 1
# 1.16 -> 1
# 2.0 -> 2.4
# 1.78 -> 1.5
# 2.3 -> 2.4
# 3.1 -> 3.1
# 3.67 -> 4.0
# 1.1 -> 1
# 0.3 -> 0.3
In both matrices the differences/spacing between the values are irregular. Using "ceil", "floor", "round" I have no chance to solve this problem... (or only with regular spacing)
Thanks a lot for any kind of help!
Reik

採用された回答

Walter Roberson
Walter Roberson 2012 年 3 月 7 日
I think maybe you want interp1() with the 'nearest' option.
  1 件のコメント
Reik
Reik 2012 年 3 月 7 日
Gna - yes, thats possible, of course. I'm still to stupid to see the easy way. :/
Thank you a lot for the eye opener! :)
R.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by