# smooth a surface plot

조회 수: 112(최근 30일)
Lauren E 2015년 4월 2일
댓글: imran saeed 2021년 2월 15일
I have an array of data which I'm plotting using the surface function. I'd like to smooth the data but interp2 doesn't work since I don't have a mesh (I'm plotting data, not a function). Is there a way I can smooth this?
My code isn't much to look at:
surface = surf(P1,P2,L);
where P1, P2 and L are imported from a data file.

댓글을 달려면 로그인하십시오.

### 답변(1개)

Andrew Newell 2015년 4월 2일
편집: Andrew Newell 2015년 4월 2일
You can make a mesh:
[P1,P2] = meshgrid(P1,P2);
Then use interp2.
EDIT: Corrected typo.
##### 댓글 수: 5표시숨기기 이전 댓글 수: 4
imran saeed 2021년 2월 15일
Based on above discussion I made this funciton, it will make coding easier, you can call this function many times to make your function smoother and smoother,
function [X,Y,Z]=smooth_spline(x,y,z)
n=length(x); sp=min(x); ep=max(x);
X=linspace(sp,ep,2*n);
sp=min(y); ep=max(y);
Y=linspace(sp,ep,2*n);
[Kxx,Kyy]=meshgrid(X,Y);
Z = interp2(x,y,z,Kxx,Kyy,'spline');
end

댓글을 달려면 로그인하십시오.

### 범주

Find more on Interpolation in Help Center and File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by