How to interpolate missing range between curves?

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.

 Réponse acceptée

Cam Salzberger
Cam Salzberger le 6 Oct 2017
Modifié(e) : Cam Salzberger le 6 Oct 2017
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

5 commentaires

Ince
Ince le 6 Oct 2017
Hello Cam,
yes, I have each of the x and y values for each line stored in a separate variable. The end of one section occurs at the same x-value as the beginning of the next, only between the blue and purple curve it isn't the case. A continous line between the curves is sufficent. I tried your suggestion but became this error: "Error using horzcat Dimensions of matrices being concatenated are not consistent."
You may have a mix between row and column vectors, e.g. x1, y1 are row vectors whereas x2, y2 are column. To work with column vectors only, use linear indexing:
xAll = [x1(:); x2(:); x3(:); x4(:); x5(:)] ;
yAll = [y1(:); y2(:); y3(:); y4(:); y5(:)] ;
Ince
Ince le 6 Oct 2017
Oh I'm sorry, for each curve I have a Xx4-matrix, in the second column are the x and in 4th the y-values. I tried:
xAll = [x1(:,2) x2(:,2) x3(:,2) x4(:,2) x5(:,2)] ;
yAll = [y1(:,4) y2(:,4) y3(:,4) y4(:,4) y5(:,4)] ;
and became the above error. But it works with ";".
But it looks so although there is no failure in the order of xAll and yAll :-/
Looks like the line just goes backwards for the curved portion. Easy fix:
xAll = [x1(:,2); x2(end:-1:1,2); x3(:,2); x4(:,2); x5(:,2)] ;
yAll = [y1(:,2); y2(end:-1:1,2); y3(:,2); y4(:,2); y5(:,2)] ;
Ince
Ince le 6 Oct 2017
Thank youuu!!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Data Exploration dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by