Once wasted on the following problem:
I have a matrix of depth values in a specific spatial area. I am defining a string in a domain and I am deleting a value below this string.
The code uses a function findnearestto find the index of an array element that is closest to a specific value.
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')
The resulting depth matrix is as follows:

represented with help contourlooks like this:

I want to rotate the depth matrix by an angle ( -pi/2-a?) Or apply some transformation to it, so that the depth contours become perpendicular to the line parallel to the first row:

I'm just different rotation matrices, but without good results ...