how to make matrix plot smooth in matlab

前端 未结 1 1606
无人共我
无人共我 2021-01-28 17:28

\"enter

Like the picture above. How can I make the picture more smooth. Or narrow down the

相关标签:
1条回答
  • 2021-01-28 18:16

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

    enter image description here

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

    enter image description here

    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!

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

    ylim([yMin yMax])
    
    0 讨论(0)
提交回复
热议问题