
Fill gap between two lines
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
How do I fill (connect) the gap between the lines in my plot?
Wd=2.42*10^3;
Ws=3.11*10^3;
Wt=6.22*10^3;
L=18.090;
a=0.3;
b=0.4;
D=Wd*L;
S=Ws*L;
T=Wt*b*L;
P=12.5*10^3;
Ra = (2*P*(1-a)+D+S+T*b)/2;
Rb = (2*P*a+D+S+T*(2-b))/2;
T1 = @(x) x*(Ws+Wd)-Ra;
T2 = @(x) x*(Ws+Wd)-Ra+P;
T3 = @(x) Rb-(L-x)*(Wt+Wd+Ws);
fplot(T1,[0,a*L])
hold on
fplot(T2,[a*L,L-b*L])
fplot(T3,[L-b*L,L])
ylabel('Tvärkraft [N]');
xlabel('x[m]')
title('T-diagram')

0 Kommentare
Antworten (1)
Image Analyst
am 1 Mär. 2020
Bearbeitet: Image Analyst
am 2 Mär. 2020
Just plot each line and then plot another line between the end of line 1 and the beginning of line 2. This will do it.
Ra = (2*P*(1-a)+D+S+T*b)/2;
Rb = (2*P*a+D+S+T*(2-b))/2;
numPoints = 100
T1 = @(x) x*(Ws+Wd)-Ra;
T2 = @(x) x*(Ws+Wd)-Ra+P;
T3 = @(x) Rb-(L-x)*(Wt+Wd+Ws);
x1 = linspace(0, a*L, numPoints);
x2 = linspace(a*L,L-b*L, numPoints);
x3 = linspace(L-b*L,L, numPoints);
y1 = T1(x1);
y2 = T2(x2);
y3 = T3(x3);
plot(x1, y1, '-', 'LineWidth', 3);
hold on;
plot(x2, y2, '-', 'LineWidth', 3);
plot(x3, y3, '-', 'LineWidth', 3);
% Plot black line that jumps the gap between line 1 and line 2.
plot([x1(end), x2(1)], [y1(end), y2(1)], 'k-', 'LineWidth', 3);
ylabel('Tvärkraft [N]');
xlabel('x[m]')
title('T-diagram')
grid on;

2 Kommentare
Image Analyst
am 2 Mär. 2020
You're welcome Philip. The forum etiquette is to click the link to "Accept this answer" for the best answer you get (you can only accept one answer in the event there are multiple answers.). Thanks in advance. ?
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!