Fill gap between two lines
이전 댓글 표시
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
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
2020년 3월 2일
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. ?
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!