Hi,
I understand you are trying to find the X and Y values for the level Z = 1. According to the query, the z-coordinates you have given as input to the ‘contourf’ function do not contain 1.
You can use a list of levels where the contour lines will be displayed and include 1 in it.
Refer to the following code:
x = linspace(-2*pi,2*pi);
y = linspace(0,4*pi);
[X,Y] = meshgrid(x,y);
Z = sin(X) + cos(Y);
% Specify 10 levels, and explicitly include 1 in the list of levels
levels = [linspace(-pi/2,1,4) 1 linspace(1,pi/2,5)];
M = contourf(X,Y,Z,levels);
% To check if 1 is part of the levels, get the list of levels from the contour matrix
levelList = findAllLevels(M);
function levels = findAllLevels(M)
% This helper function extracts all levels/heights from the contour matrix returned by contourf
n=size(M,2);
j=1;
i=1;
while i+M(2,i)+1<n
i = i+M(2,i)+1;
levels(j) = M(1,i);
j = j+1;
end
end
This would ensure a contour line is plotted at Z = 1, and the x and y coordinates at this contour line can be obtained through the contour matrix ‘M’. You can observe the same by inspecting ‘M’ in the editor window:
Please refer to the following MATLAB documentation for further reference: