绘制曲线而不是直线 [英] Plot a curve rather than a line
本文介绍了绘制曲线而不是直线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在matlab中,我有一个向量,例如x
和一个x
函数,例如y
.我想在Matlab中绘制x
和y
.
In matlab, I have a vector, say x
and a function of x
say y
. I want to plot x
and y
in matlab.
问题是我想要平滑的曲线(不是平滑的纹理而是可区分的,并且没有锐利的弯曲). Matlab带有图,只需将这些点连接起来即可,并且绘制的曲线具有急剧的弯曲.
The problem is I want smooth curve (not in a sense of smooth texture but differentiable, and without sharp bends). Matlab, with plot, simply joins the points and the plotted curve has sharp bends.
有没有办法解决这个问题?
Is there a way I can resolve this?
推荐答案
跟随 wakjah ,您需要将x
和y
插值到更多采样点
Following Dan and wakjah, what you need is to interpolate x
and y
to more sample points
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
这篇关于绘制曲线而不是直线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文