I need a graph to be smooth
2 次查看(过去 30 天)
显示 更早的评论
Here is the code I have:
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);
xlabel('width')
ylabel('length')
title('Depth of Paugus Bay')
I tried adding this to smooth it, but it wasn't as smooth as I needed:
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');
zhat = conv2(K,z)./conv2(ones(size(z)),K);
surf(zhat)
0 个评论
回答(1 个)
John D'Errico
2022-11-30
You asked this question before. I answered it. In fact, you even show the code I wrote. And you accepted my answer then as I recall.
It you want it to be smoother, then the simple answer is to use a larger smoothing kernel!
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);
xlabel('width')
ylabel('length')
n = 5; % NOTE THE DIFFERENCE!
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');
zhat = conv2(K,z)./conv2(ones(size(z)),K);
surf(zhat)
Or you might build a gaussian blur instead. Or a variation of Savitsky-Golay filter, in 2-d. The above is easy, because it can be done almost trivially.
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!