How to connect two plot line together?
42 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
How to link the red line and blue line together?
3 Kommentare
Walter Roberson
am 31 Okt. 2019
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.
Antworten (1)
Subhadeep Koley
am 4 Nov. 2019
Bearbeitet: Subhadeep Koley
am 4 Nov. 2019
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;
Hope this helps!
0 Kommentare
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!