下午浪费在以下问题上:
我有一个深度值矩阵,位于某个空间域中。我在该域中定义一条线,并擦除该线下方的值。
代码使用
生成的深度矩阵如下所示: 使用
我有一个深度值矩阵,位于某个空间域中。我在该域中定义一条线,并擦除该线下方的值。
代码使用
findnearest
函数查找数组中距离某个值最近的元素的索引。clear all
close all
dx = 5;
dz = 1;
%angle between line and ground
a=atan(0.05);
%%%define domain
xi = 0:dx:20e3;
zi = 0:dz:1000;
m=length(zi);
n=length(xi);
%create grid
[x,z] = meshgrid(xi,zi);
%z where line starts
zs = 700;
%set line
for i = 1:findnearest(xi,zi(zs)*1/a)
xind(i) = i;
zind(i) = findnearest(zi, fix(-xi(i)*a +zi(zs)));
end
depth = repmat(zi',1,n); %simply the coordinate zi repeated for all xi
%calculate distance from the line
for ii=1:n %for every x
zslope = -a*xi(ii)+zi(zs);%equation of the line
zz(ii)=zslope;
if zslope>=0 %if the line is still in the domain (z>0)
for jj=1:m %for every z
if zi(jj)>=zslope %above the line
Zs(jj,ii) = zi(jj)-zslope; %height above the line
elseif zi(jj)<zslope %below the line (ground)
%
Zs(jj,ii)=NaN;
end
end%for on z
elseif zslope<0 %the line is no longer in the domain
for jj=1:m %for every z
Zs(jj,ii) = zi(jj)-zslope; %height above the line
end
end
end%for on x
figure
imagesc(Zs)
colorbar
title('distance from the line')
%zone above the line
maskINT=zeros(m,n);
inds = find(Zs>=0); %erase values under the line
maskINT(inds)=1;
figure
imagesc(depth);colorbar
title('depth')
figure
imagesc(depth.*maskINT);colorbar
title('depth above the line')
figure
contour(depth.*maskINT);colorbar
set(gca,'YDir','Reverse')
title('depth')
生成的深度矩阵如下所示: 使用
contour
表示如下:
我想将深度矩阵旋转一个角度(-pi/2-a
?)或对其应用某些变换,使深度轮廓垂直于与第一条线平行的线:
我尝试了各种旋转矩阵,但效果不佳...
imrotate(depth,angleInDegrees)
吗? - Leander Moesinger