smooth line in plot

5 次查看(过去 30 天)
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