【问题标题】:Plot a curve rather than a line绘制曲线而不是直线
【发布时间】:2015-06-28 02:48:34
【问题描述】:

在 matlab 中,我有一个向量,比如 x 和一个函数 x,比如 y。我想在matlab中绘制xy

问题是我想要平滑的曲线(不是平滑的纹理感,而是可微分的,并且没有急弯)。 Matlab,带有绘图,只需将点连接起来,绘制的曲线有急剧的弯曲。

有什么办法可以解决这个问题吗?

【问题讨论】:

  • 你需要插值,用'cubic'看interp1函数:mathworks.com/help/matlab/ref/interp1.html。请注意,'spline' 将有一个连续的一阶和二阶导数,'cubic' 可能会给你一个更好看的曲线,但会有一个不连续的二阶导数,但我认为这对于你所追求的来说是可以接受的
  • 绘制更多点。在没有看到任何代码的情况下,很难说更具体的关于您可能遇到的问题
  • @Dan 谢谢!会看看它。和: wakjah,这不是特定的问题。由于计算时间限制,不可能取很多点(考虑嵌套循环)。

标签: matlab plot


【解决方案1】:

Danwakjah 之后,您需要将xy 插值到更多样本点

plot( x, y, '+r' ); % plot the original points
n = numel(x); % number of original points
xi = interp1( 1:n, x, linspace(1, n, 10*n) ); % new sample points 
yi = interp1(   x, y, xi );
hold all;
plot( xi, yi ); % should be smooth between the original points

【讨论】:

    猜你喜欢
    • 2016-03-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多