smooth line in plot

조회 수: 5 (최근 30일)
Dion Theunissen
Dion Theunissen 2021년 6월 2일
댓글: Star Strider 2021년 6월 2일
hi,
I have a plot which contains 6 points. Now i want to smooth the line. How can I do that?
a = 0 1.56809885737654 1.00861433623079
1 0.477810012662993 0.172723989683935
2 0.307057557611696 0.0369907704137005
3 0.301187535069457 0.0712463310209048
4 0.250962057090148 0.0847637163609592
5 0.208201848906565 0.0233647321748921

채택된 답변

Star Strider
Star Strider 2021년 6월 2일
a = [0 1.56809885737654 1.00861433623079
1 0.477810012662993 0.172723989683935
2 0.307057557611696 0.0369907704137005
3 0.301187535069457 0.0712463310209048
4 0.250962057090148 0.0847637163609592
5 0.208201848906565 0.0233647321748921];
ai = linspace(min(a(:,1)),max(a(:,1)));
a1 = interp1(a(:,1), a(:,2:end), ai, 'pchip');
figure
plot3(a(:,1), a(:,2), a(:,3), 'p')
hold on
plot3(ai, a1(:,1), a1(:,2), '-r')
hold off
grid on
figure
plot(a(:,2), a(:,3), 'p')
hold on
plot(a1(:,1), a1(:,2), '-r')
hold off
grid
axis('equal')
ai = linspace(max(a(:,2)),min(a(:,2)));
a2 = interp1(a(:,2), a(:,3), ai, 'makima');
figure
plot(a(:,2), a(:,3), 'p')
hold on
plot(ai, a2, '-r')
hold off
grid
axis('equal')
.
  댓글 수: 2
Dion Theunissen
Dion Theunissen 2021년 6월 2일
Unfortunately this is not correct. a(:,1) is my x axis, a(:,2) is my y axis. So the line has to go till atleast 5 on the x axis
Star Strider
Star Strider 2021년 6월 2일
In that instance, just use the first part of my Answer, that being (with a few tweaks) —
a = [0 1.56809885737654 1.00861433623079
1 0.477810012662993 0.172723989683935
2 0.307057557611696 0.0369907704137005
3 0.301187535069457 0.0712463310209048
4 0.250962057090148 0.0847637163609592
5 0.208201848906565 0.0233647321748921];
ai = linspace(min(a(:,1)),max(a(:,1)));
a1 = interp1(a(:,1), a(:,2:end), ai, 'makima');
figure
plot3(a(:,1), a(:,2), a(:,3), 'p')
hold on
plot3(ai, a1(:,1), a1(:,2), '-r')
hold off
grid on
xlabel('X')
ylabel('Y')
zlabel('Z')
axis('equal')
.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by