How to filter out the elevation higher than 0

1 vue (au cours des 30 derniers jours)
Nicholas Deosaran
Nicholas Deosaran le 10 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 commentaires
Image Analyst
Image Analyst le 10 Oct 2021
Make it easy for us to help you. Please attach 'crm_vol2.nc'.
Nicholas Deosaran
Nicholas Deosaran le 10 Oct 2021
I would love to attached the 'crm_vol2.nc' file but it is to big to attached even when its zipped and compressed.
is the link i got the infomration from and "download NetCDF File"

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 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(:)];
  3 commentaires
Walter Roberson
Walter Roberson le 10 Oct 2021
xyz = [xp(:), yp(:), zp(:)];
xyz(xyz(:,3) > 0, :) = [];
Nicholas Deosaran
Nicholas Deosaran le 13 Oct 2021
Thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by