How to filter out the elevation higher than 0
2 views (last 30 days)
Show older comments
Nicholas Deosaran
on 10 Oct 2021
Commented: Nicholas Deosaran
on 13 Oct 2021
Hello all,
I wrote my code to get the elevation of the Cape Fear Area to make a mesh grid.
I wanted to know if there is a way to filter out any elvation higher than 0.
filename = 'crm_vol2.nc';
meta = ncinfo(filename);
disp('Variable List');
names = {meta.Variables.Name}';
% there are 3 variables inside the netCDF file: x, y, z
x = ncread(filename, 'x');
y = ncread(filename, 'y');
z = ncread(filename, 'z');
z = z';
min_x = min(x);
max_x = max(x);
min_y = min(y);
max_y = max(y);
dxy = 8.3333e-04;
[xv, yv] = meshgrid(min_x:dxy:max_x,min_y:dxy:max_y);
dx = dxy;
dy = dxy;
x_low = -78.22; % longitude low
x_up = -77.30; % longitude up
y_low = 33.82; % latitude low
y_up = 34.33; % latitude up
[xp, yp] = meshgrid(x_low:dx:x_up, y_low:dy:y_up);
zp = interp2(xv, yv, z, xp, yp); % makes the zp array for depth
% export xp, yp, and zp into text file to be imported into MIKE mesh generator!
% for loop to get needed data for xp, yp, and zp
[m,n] = size(xp);
xyz = zeros (m*n,3) ;
count = 0;
for i = 1:m
for j = 1:n
count = count+1;
xyz (count, 1 ) = xp (i,j);
xyz (count, 2 ) = yp (i,j);
xyz (count, 3 ) = zp (i,j);
end
end
xyz = xyz(1:count,:);
save mesgrid.xyz xyz -ascii
This code just takes all the data and put them in coloums and able to save it as an .xyz file.
2 Comments
Accepted Answer
Jan
on 10 Oct 2021
I do not see, where your filter out elevations greator 0.
It is faster to call interp2 with vectors as coordinates. So avoid calling meshgrid but provide the vectors directly.
Replace:
[m,n] = size(xp);
xyz = zeros (m*n,3) ;
count = 0;
for i = 1:m
for j = 1:n
count = count+1;
xyz (count, 1 ) = xp (i,j);
xyz (count, 2 ) = yp (i,j);
xyz (count, 3 ) = zp (i,j);
end
end
by
xyz = [xp(:), yp(:), zp(:)];
More Answers (0)
See Also
Categories
Find more on NetCDF 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!