How to filter out the elevation higher than 0

2 ビュー (過去 30 日間)
Nicholas Deosaran
Nicholas Deosaran 2021 年 10 月 10 日
コメント済み: Nicholas Deosaran 2021 年 10 月 13 日
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 件のコメント
Image Analyst
Image Analyst 2021 年 10 月 10 日
Make it easy for us to help you. Please attach 'crm_vol2.nc'.
Nicholas Deosaran
Nicholas Deosaran 2021 年 10 月 10 日
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"

サインインしてコメントする。

採用された回答

Jan
Jan 2021 年 10 月 10 日
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 件のコメント
Walter Roberson
Walter Roberson 2021 年 10 月 10 日
xyz = [xp(:), yp(:), zp(:)];
xyz(xyz(:,3) > 0, :) = [];
Nicholas Deosaran
Nicholas Deosaran 2021 年 10 月 13 日
Thank you!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNetCDF についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by