I need to smooth a 3d graph

3 views (last 30 days)
Shayleah Gunning-Lavoie
Shayleah Gunning-Lavoie on 26 Nov 2022
this is tha data I have now and i need to smooth it out thank you! there is no errors or red text in the following code
x=1:10;
y=1:21;
z=[0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 -9 0 0 0 0; 0 0 0 0 -5 -7 0 0 0 0; 0 0 -10 -25 -15 -5 0 0 0 0; 0 -20 -32 -46 -27 -7 0 0 0 0; 0 -17 -61 -82 -21 0 0 0 0 0; 0 -12 -28 -52 -30 -12 0 0 0 0; 0 -22 -43 -79 -53 -30 -12 0 0 0; 0 -15 -38 -63 -92 -68 -33 0 0 0; 0 0 -15 -37 -61 -49 -22 0 0 0; 0 0 0 -17 -56 -30 -17 0 0 0; 0 0 0 -15 -56 -30 -17 0 0 0; 0 0 -15 -32 -54 -94 -79 -31 0 0; 0 0 -21 -15 -25 -52 -37 -20 0 0; 0 0 -15 -40 -70 -49 -20 -15 0 0; 0 0 -11 -23 -14 -20 -46 -29 -14 0; 0 0 0 -10 -27 -39 -25 -15 0 0; 0 0 0 -15 -32 -56 -26 -10 0 0; 0 0 0 -10 -17 -25 -15 0 0 0; 0 0 0 0 -20 -10 0 0 0 0; 0 0 0 0 -5 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0];
surf(z);

Answers (1)

John D'Errico
John D'Errico on 26 Nov 2022
x=1:10;
y=1:21;
z=[0 0 0 0 0 0 0 0 0 0; 0 0 0 0 0 -9 0 0 0 0; 0 0 0 0 -5 -7 0 0 0 0; 0 0 -10 -25 -15 -5 0 0 0 0; 0 -20 -32 -46 -27 -7 0 0 0 0; 0 -17 -61 -82 -21 0 0 0 0 0; 0 -12 -28 -52 -30 -12 0 0 0 0; 0 -22 -43 -79 -53 -30 -12 0 0 0; 0 -15 -38 -63 -92 -68 -33 0 0 0; 0 0 -15 -37 -61 -49 -22 0 0 0; 0 0 0 -17 -56 -30 -17 0 0 0; 0 0 0 -15 -56 -30 -17 0 0 0; 0 0 -15 -32 -54 -94 -79 -31 0 0; 0 0 -21 -15 -25 -52 -37 -20 0 0; 0 0 -15 -40 -70 -49 -20 -15 0 0; 0 0 -11 -23 -14 -20 -46 -29 -14 0; 0 0 0 -10 -27 -39 -25 -15 0 0; 0 0 0 -15 -32 -56 -26 -10 0 0; 0 0 0 -10 -17 -25 -15 0 0 0; 0 0 0 0 -20 -10 0 0 0 0; 0 0 0 0 -5 0 0 0 0 0; 0 0 0 0 0 0 0 0 0 0];
surf(z)
Simplest is a convolution based blur. This one is a simple distance weighting:
n = 3;
n2 = (n-1)/2;
[x,y] = meshgrid((1:n) - n2);
K = 1./(1 + sqrt((x - n2).^2 + (y - n2).^2));
K = K/sum(K,'all')
K = 3×3
0.0889 0.1074 0.0889 0.1074 0.2147 0.1074 0.0889 0.1074 0.0889
zhat = conv2(K,z)./conv2(ones(size(z)),K);
surf(zhat)

Community Treasure Hunt

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

Start Hunting!