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.

 채택된 답변

Cam Salzberger
Cam Salzberger 2017년 10월 6일
편집: Cam Salzberger 2017년 10월 6일
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

Ince
Ince 2017년 10월 6일
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 2017년 10월 6일
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 2017년 10월 6일
Thank youuu!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Data Exploration에 대해 자세히 알아보기

질문:

2017년 10월 6일

댓글:

2017년 10월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by