Round towards target matrix

6 views (last 30 days)
Reik
Reik on 7 Mar 2012
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

Accepted Answer

Walter Roberson
Walter Roberson on 7 Mar 2012
I think maybe you want interp1() with the 'nearest' option.
  1 Comment
Reik
Reik on 7 Mar 2012
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!