Fill gap between two lines

2 次查看(过去 30 天)
Philip Gerber
Philip Gerber 2020-3-1
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')

回答(1 个)

Image Analyst
Image Analyst 2020-3-1
编辑:Image Analyst 2020-3-2
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 个评论
Philip Gerber
Philip Gerber 2020-3-2
Thanks alot for the help! :)
Image Analyst
Image Analyst 2020-3-2
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. ?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by