简体   繁体   English

如何在matlab中使矩阵图平滑

[英]how to make matrix plot smooth in matlab

在此输入图像描述

Like the picture above. 如上图所示。 How can I make the picture more smooth. 如何使图片更加流畅。 Or narrow down the scope of y axis. 或者缩小y轴的范围。

The data is from a 2D matrix. 数据来自2D矩阵。

Then I plot with plot('data') 然后我用plot('data')

Please feel free to throw any ideas. 请随意抛出任何想法。

One way to smooth the line involves non-linear interpolation of data between sample points. 平滑线的一种方法涉及采样点之间的数据的非线性插值。 When you do plot(x,y,'o-') , MATLAB automatically plots a connect-the-dots style piece-wise linear series. 当你plot(x,y,'o-') ,MATLAB会自动绘制一个连接点样式的分段线性系列。 However, you can plot without the automatic connecting lines, using just markers for the data points, and plot your own smoothed series (or just plot the smoothed series!). 但是,您可以在没有自动连接线的情况下进行绘图,仅使用数据点的标记,并绘制自己的平滑系列(或仅绘制平滑的系列!)。 For example, start with the default connecting lines: 例如,从默认连接线开始:

x = 1:10;
y = rand(numel(x),1);
plot(x,y,'r-o')

在此输入图像描述

Now, one way to generate "smoothed" data is by using non-linear interpolation for the curve (no longer a line) between data points. 现在,生成“平滑”数据的一种方法是对数据点之间的曲线(不再是直线)使用非线性插值。 We can use interp1 with the 'cubic' interpolation method to do this: 我们可以使用interp1'cubic'插值方法来做到这一点:

xx = 1:0.1:10; % line is inherently higher sample rate
yy = interp1(x,y,xx,'cubic');
plot(x,y,'bo',xx,yy,'k-')

在此输入图像描述

What this really boils down to is not a MATLAB trick at all -- just plot interpolated data . 这真正归结为不是MATLAB技巧 - 只是绘制插值数据 However, ask yourself if you would be better off just plotting the actual data. 但是,问问自己是否最好只绘制实际数据。 There is good reason why plot just does connect-the-dots! 有充分的理由为什么plot只是连接点!

Regarding the y axis range, you can set the min and max without touching the x axis via ylim as follows, 关于y轴范围,您可以设置最小值和最大值,而不通过ylim触摸x轴,如下所示,

ylim([yMin yMax])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM