MATLAB: How to interpolate missing range between curves

interpolationmissing datasets

Hi, I have the x and y values for the depicted curves, but I want to connect the ends/beginnings of the curves with each other to have only one line. How can I interpolate the missing ranges? I have read some posts in this community but I don't understand how to apply the solutions to my case. I would be thankful if someone can give a suitable example.

Best Answer

Hello Ince,
I am assuming that you have each of the x and y values for each line stored in a separate variable (and for this example, that they are all row vectors). If you are simply looking to plot it all as a continuous line, you can just do this:
xAll = [x1 x2 x3 x4 x5];
yAll = [y1 y2 y3 y4 y5];
plot(xAll, yAll)
to simulate linear interpolation (since it'll just draw a line between the last point of one section and the first point of the next).
From the image, it looks like the end of one section occurs at the same x-value as the beginning of the next. This means that traditional interpolation doesn't really make sense, as if you were to try to interpolate at that x-value, the answer could be any y-value between the endpoints. Of course, interpolating at that y-value and getting the correct x-value is valid, but you can do that without anything special.
So if you're trying to do more than just draw a continuous line, can you explain in more detail what you are trying to do with this interpolation?
-Cam
Related Question