How to filter out the elevation higher than 0
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
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(:)];
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 NetCDF 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!