MATLAB: Boundary line for contour

boundarycontourf

Hello,
I want to draw a boundary line for my contour
you can see my contour (without bondary) and a contour with boundary (desired)
you can see my contour (without bondary)
here is my code:
clc,clear,close all;
% syms z y ;
B = 10;
H = 5;
C = 10;
L1 = 1;
Ri = B/2 + L1;
Rf = C + B/2 + L1;
y = linspace(-25,0,1000);
z = linspace(0,28,1000);
[Z,Y] = meshgrid(z,y);
r1 = sqrt((Y.^2)+(Z.^2));
r = abs(sqrt((Y.^2)+(Z.^2)) - Rf);
beta = asin( Z ./ sqrt((Y.^2)+(Z.^2)) );
beta(1000,1) = 0;
Rbeta = Ri + (2.*beta.*(Rf-Ri)./pi);
Rt0 = B/2+L1;
Rmaxtb = (Rt0.*Rbeta)./Ri;
Vmbeta = (2*(pi^2)*((B+(2*L1))^2)) ./ ((((2*L1*pi)+(pi*B)+(4.*beta.*C)).^2));
% Calculate the distance for condition
Rt00 = (B/2-L1);
Rmaxtbb = (Rt00.*Rbeta)./Ri;
% End
for i = 1:1:1000
for j = 1:1:1000
if r(i,j)>Rbeta(i,j) | r1(i,j)>(Rf+Rmaxtbb(i,j))
Vbeta(i,j)=0;
else
Vbeta(i,j) = Vmbeta(i,j) * (1 - ((r(i,j)^2) / (Rmaxtb(i,j)^2)));
end
end
end
ZZ = Z./B;
YY = Y./B;
contourf(ZZ,YY,Vbeta,100,'edgecolor','none')
colormap( flipud(gray(256)) )
colorbar
xlabel('z/D')
ylabel('y/D')
any help is appreciated

Best Answer

Sometimes, a bit of absolute creativity (‘thinking outside the contour) is necessary.
I first did a meshc plot of your matrices to see what the ‘Vbeta’ matrix looked like in 3D. It has a sllight elevation with steep transitions at the edges. That led to experiments using the gradient function to calculate numerical derivatives of the ‘Vbeta’ matrix, and that led to this result (with code previous to this not copied here):
ZZ = Z./B;
YY = Y./B;
contourf(ZZ,YY,Vbeta,100,'edgecolor','none')
colormap( flipud(gray(256)) )
colorbar
xlabel('z/D')
ylabel('y/D')
[~,dY] = gradient(Vbeta);
hold on
contour(ZZ.*(dY~=0),YY.*(dY~=0),ones(size(dY)).*(dY~=0), [0 1], '--k')
hold off
producing this plot:
I have no idea how robust this approach would be to similar plots, however it appears to work here. It uses a second contour call and logical indexing (of a sort) to ptroduce the necessary contours.