如何在matlab中使矩阵图平滑 [英] how to make matrix plot smooth in matlab

查看:1258
本文介绍了如何在matlab中使矩阵图平滑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像上面的图片一样.如何使图片更平滑.或缩小y轴的范围.

Like the picture above. How can I make the picture more smooth. Or narrow down the scope of y axis.

数据来自2D矩阵.

然后我用plot('data')

请随时提出任何想法.

推荐答案

一种平滑直线的方法是在采样点之间进行非线性数据插值.当您执行 plot(x,y,'o-') 时,MATLAB会自动绘制连接图点样式分段线性系列.但是,您可以在没有自动连接线的情况下进行绘图,仅使用标记作为数据点,然后绘制自己的平滑序列(或仅绘制平滑序列!).例如,从默认的连接线开始:

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. 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')

现在,一种生成平滑"数据的方法是对数据点之间的曲线(不再是直线)使用非线性插值.我们可以将 interp1 'cubic'插值方法一起使用做到这一点:

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:

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

这真正归结为根本不是MATLAB的窍门-仅绘制插值数据.但是,问问自己是否最好只绘制实际数据. plot只是进行点连接是有充分的理由!

What this really boils down to is not a MATLAB trick at all -- just plot interpolated data. 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!

关于y轴范围,您可以通过 ylim 如下,

Regarding the y axis range, you can set the min and max without touching the x axis via ylim as follows,

ylim([yMin yMax])

这篇关于如何在matlab中使矩阵图平滑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆