Round towards target matrix

6 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by