How to connect two plot line together?

How to link the red line and blue line together?

댓글 수: 3

hold on
plot([last_x_of_red, first_x_of_blue], [last_y_of_red, first_y_of_blue])
hold off
for appropriate values of those variables.
If you do not have those values available, then it is possible to retrieve them from the existing graphics objects, but it is easier just to use values from existing variables.
Zeng Zhi Tee
Zeng Zhi Tee 2019년 10월 31일
Thanks. How do i move the blue line so that it is directly connected to the red line without adding one more line?
Walter Roberson
Walter Roberson 2019년 10월 31일
Add last y of red minus first y of blue to all blue y.
It is difficult to tell by eye; there just might be a small x gap ae well that requires an x adjustment.

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

답변 (1개)

Subhadeep Koley
Subhadeep Koley 2019년 11월 4일
편집: Subhadeep Koley 2019년 11월 4일

0 개 추천

Hi, you can use the code below to connect the red line with the blue line directly without adding any third line.
% Demo figure for example
x =1:10;
y1 = 1:3;
figure;plot(x(1:3),y1,'r');
hold all;
y2 = 1:-1:-10;
plot(x(3:10),y2(1:8),'b');
axis([1 10 -5 5]);
hold off;
% Extract datas from the figure if you dont have the original data
fig = gcf;
axObjs = fig.Children;
dataObjs = axObjs.Children;
y1_fig = dataObjs(2).YData;
y2_fig = dataObjs(1).YData;
x1_fig = dataObjs(2).XData;
x2_fig = dataObjs(1).XData;
% Calculate the difference
differ = abs(y1_fig(end) - y2_fig(1));
y2_fig = y2_fig + differ;
% Plot the connected graph
figure;plot(x1_fig,y1_fig,'r');
hold all;
plot(x2_fig,y2_fig,'b');
axis([1 10 -5 5]);
hold off;
mon.png
Hope this helps!

카테고리

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

태그

질문:

2019년 10월 31일

편집:

2019년 11월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by