非因变量图的光滑图

编程入门 行业动态 更新时间:2024-10-23 09:36:25
本文介绍了非因变量图的光滑图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

假设我们有以下数据:

A1= [41.3251 18.2350 9.9891 36.1722 50.8702 32.1519 44.6284 60.0892 58.1297 34.7482 34.6447 6.7361 1.2960 1.9778 2.0422]; A2=[86.3924 86.4882 86.1717 85.8506 85.8634 86.1267 86.4304 86.6406 86.5022 86.1384 86.5500 86.2765 86.7044 86.8075 86.9007];

当我使用plot(A1,A2);绘制上述数据时,得到以下图表:

When I plot the above data using plot(A1,A2);, I get this graph:

有什么方法可以使图形看起来像三次方图一样平滑吗?

Is there any way to make the graph look smooth like a cubic plot?

推荐答案

可以.您可以在关键点之间进行插值.但是,这将需要一些技巧.盲目地将插值与MATLAB的任何命令结合使用是行不通的,因为它们要求增加独立轴(在您的情况下为x轴).您目前无法使用您的数据执行此操作……至少是开箱即用的.因此,您必须创建一个虚拟的值列表,该值的范围从1到与A1(或A2,因为它们的大小均相等)中的元素一样多,以创建独立的轴并内插 both 阵列.较细的间距由要在绘图中引入的新点的总数控制.这些点将在虚拟列表的范围内定义,但是随着您增加新点的总数,每个点之间的间隔将减小.通常,添加的点越多,间距就越小,因此绘图应更平滑.完成此操作后,将最终值绘制在一起.

Yes you can. You can interpolate in between the keypoints. This will require a bit of trickery though. Blindly using interpolation with any of MATLAB's commands won't work because they require that the independent axes (the x-axis in your case) to increase. You can't do this with your data currently... at least out of the box. Therefore you'll have to create a dummy list of values that span from 1 up to as many elements as there are in A1 (or A2 as they're both equal in size) to create an independent axis and interpolate both arrays independently by specifying the dummy list with a finer spacing in resolution. This finer spacing is controlled by the total number of new points you want to introduce in the plot. These points will be defined within the range of the dummy list but the spacing in between each point will decrease as you increase the total number of new points. As a general rule, the more points you add the less spacing there will be and so the plot should be more smooth. Once you do that, plot the final values together.

这里有一些代码供您运行.我们将使用 interp1 为我们和大部分工作.函数 linspace 在虚拟对象中创建更精细的点网格列表以方便插值. N将是您要绘制的所需点的总数.我现在将其设为500,这意味着将使用您的原始数据进行500点插值.通过增加(或减少)点总数进行实验,看看这对数据的平滑度有什么影响.

Here's some code for you to run. We will be using interp1 to perform the interpolation for us and most of the work. The function linspace creates the finer grid of points in the dummy list to facilitate the interpolation. N would be the total number of desired points you want to plot. I've made it 500 for now meaning that 500 points will be used for interpolation using your original data. Experiment by increasing (or decreasing) the total number of points and seeing what effect this has in the smoothness of your data.

我还将使用 Piecewise三次Hermite插值多项式或pchip作为插值方法,如果您想获取技术知识,这基本上是三次样条插值.假设已经创建了A1和A2:

I'll also be using the Piecewise Cubic Hermite Interpolating Polynomial or pchip as the method of interpolation, which is basically cubic spline interpolation if you want to get technical. Assuming that A1 and A2 are already created:

%// Specify number of interpolating points N = 500; %// Specify dummy list of points D = 1 : numel(A1); %// Generate finer grid of points NN = linspace(1, numel(A1), N); %// Interpolate each set of points independently A1interp = interp1(D, A1, NN, 'pchip'); A2interp = interp1(D, A2, NN, 'pchip'); %// Plot the data plot(A1interp, A2interp);

我现在得到以下信息:

更多推荐

非因变量图的光滑图

本文发布于:2023-11-30 20:12:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651341.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:因变量   光滑

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!