matlab smoothing data problem

Hello matlab users
I have a 2-dimensional water depth data. When the value is negative, it is land (make_bathy)
I need to linearly smooth the relationship between land and water to prevent the difference in water depth from being too large.
As shown in plot_bathy.m (read the file in QA.zip)
Thanks in advance

 Accepted Answer

hello
I am not sure to understand your plot and where the transition land / water can be seen
nevertheless , if you need to smooth a 2D surface , I like the two following Fex submissions
code
clear all
dep=load('dep_shoal_inlet.txt');
[n,m]=size(dep);
dx=2.0;
dy=2.0;
x=[0:m-1]*dx;
y=[0:n-1]*dy;
x_sponge=[0 180 180 0 0];
y_sponge=[0 0 y(end) y(end) 0];
x_wavemaker=[240 260 260 240 240];
y_wavemaker=[0 0 y(end) y(end) 0];
wid=5;
len=6;
set(gcf,'units','inches','paperunits','inches','papersize', [wid len],'position',[1 1 wid len],'paperposition',[0 0 wid len]);
clf
figure(1),
pcolor(x,y,-dep),shading flat
cbar=colorbar;
set(get(cbar,'ylabel'),'String',' -dep (m) ')
hold on
plot(x_sponge,y_sponge,'g--','LineWidth',2)
text(10,1000,'Sponge','Color','g')
plot(x_wavemaker,y_wavemaker,'w-','LineWidth',2)
text(270,1200,'Wavemaker','Color','w')
caxis([-10 3])
xlabel('x (m)')
ylabel('y (m)')
% print -djpeg inlet_shoal.jpg
% smoothn : Fex : https://fr.mathworks.com/matlabcentral/fileexchange/25634-smoothn?s_tid=ta_fx_results
deps = smoothn(dep,1e5);
figure(2),
pcolor(x,y,-deps),shading flat
% smooth2a : Fex : https://fr.mathworks.com/matlabcentral/fileexchange/23287-smooth2a?s_tid=srchtitle
deps2 = smooth2a(dep,25,25);
figure(3),
pcolor(x,y,-deps2),shading flat

4 Comments

Sorry, I may not have expressed it clearly.
In make_bathy, the terrain file I created wanted to have a gradually rising slope like plot_bathy. plot_bathy can see the gradually rising gradient
no problem
the code below is quite the same as above , adapted to plot_bathy.m
this is the result obtained with smoothn
and with smooth2a
clear all;clc;clf
set(gcf,'color','w')
%%
m = 1024;
n = 512;
%---------------------grid size----------------------
dx = 2.0;
dy = 2.0;
lx = (n-1)*dx;
ly = (m-1)*dy;
xx = [0:dx:lx]';
yy = [0:dy:ly]';
[x,y] = meshgrid(xx,yy);
nx = length(xx); % Mglob
ny = length(yy); % Nglob
%% initial water depth
h0 = 10.0;
%% iobs - index ; water = 1
for j = 1 : n
for i = 1 : m
if ( x(i,j) >= 500 && x(i,j)<= 1024 && y(i,j)>= 1200 && y(i,j)<= 2048 )
dep(i,j) = -2;
elseif ( x(i,j) >= 500 && x(i,j)<= 1024 && y(i,j)>= 0 && y(i,j)<= 1000 )
dep(i,j) = -2;
else
dep(i,j) = h0;
end
end
end
%% check results
figure(1),
pcolor(x,y,-dep);shading interp ;colorbar
xlabel('x (m)')
ylabel('y (m)')
axis equal
% smoothn : Fex : https://fr.mathworks.com/matlabcentral/fileexchange/25634-smoothn?s_tid=ta_fx_results
deps = smoothn(dep,1e5);
figure(2),
pcolor(x,y,-deps),shading interp ;colorbar
xlabel('x (m)')
ylabel('y (m)')
axis equal
% smooth2a : Fex : https://fr.mathworks.com/matlabcentral/fileexchange/23287-smooth2a?s_tid=srchtitle
deps2 = smooth2a(dep,20,30);
figure(3),
pcolor(x,y,-deps2),shading interp ;colorbar
xlabel('x (m)')
ylabel('y (m)')
axis equal
Thank you so much
as always, my pleasure !

Sign in to comment.

More Answers (0)

Categories

Find more on Curve Fitting Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!