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 CenterFile Exchange에서 NetCDF에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by