Alex King
Alex King

Reputation: 200

How can I smooth a surface in MATLAB?

I have a surface in matlab which is plotted using the following code:

[xi, yi] = meshgrid(S/K, days);
vq = griddata(S/K, days, rbf/K, xi, yi,'natural');
mesh(xi,yi,vq)

The resulting image is quite rough, and has lots of grid lines as there are roughly 200 data points in each vector. Is it possible to plot a mesh which has a smaller number of grid points (e.g. 20) which averages out an existing meshgrid, griddata surface?

Upvotes: 2

Views: 3052

Answers (1)

nkjt
nkjt

Reputation: 7817

One option is to use conv2 on your vq data to smooth, then downsample as @Ander suggested:

n = 5; % averaging size
vq_2 = conv2(vq, ones(n)/n.^2,'same');
mesh(xi(1:20:end,1:20,end),yi(1:20:end,1:20,end),vq_2(1:20:end,1:20,end))

There will be a bit of an edge effect as by default conv2 pads with zeros.

Upvotes: 3

Related Questions