Problem 970. Piecewise linear interpolation
Given an Mx2 vector and a row of M-1 integers, output a two column vector that linearly interpolates Y times between each successive pair of values in X. Any consecutive duplicate points are to be removed.
For example
x = [1 1 ; 3 0 ; 1 1] y = [5 3]
Your output will be a two column vector that interpolates 5 times between [1 1] and [3 0] (including the boundaries in those five points), and then 3 times between [3 0] and [1 1]. The output should be:
1 1 1.5 0.75 2 0.5 2.5 0.25 3 0 2 0.5 1 1
There are Y(1)=5 points between the first two coordinate pairs of X [(1,1) and (3,0)], and Y(2)=3 points between the second and third coordinate pairs of X [(3,0) and (2 0.5)]. Notice that there is only one output point for (3,0).
You can assume that there will be no complex numbers, Inf, or NaN in x, and Y>=3 for all values of Y. Good luck!
Solution Stats
Problem Comments
-
2 Comments
It seems someone messed up the test code: the defintion of x for the first test is now in the comment line and its impossible now to solve the problem (except cheating...)
I think there is something wrong with the test.
Solution Comments
Show commentsProblem Recent Solvers538
Suggested Problems
-
15691 Solvers
-
Reverse the Words (not letters) of a String
439 Solvers
-
The Answer to Life, the Universe, and Everything
522 Solvers
-
242 Solvers
-
4446 Solvers
More from this Author80
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!