If I have a variable z at mapped locations x and y, is there way to obtain the x-y locations of the contour(s) enclosing any continuous region in which z is between two thresholds minZ and maxZ? I do not have the Image Processing toolbox but this task may be similar to image segmentation. Below I use contourf to obtain the x,y locations of the region's outer edge, but perhaps there is a better approach.
% Make a fake dataset
z = peaks;z = z(1:25, :); % Let's make different numbers of x and y elements for clarity
y = 1:size(z, 1);x = 1:size(z, 2);% Desired thresholds for the region
minZ = 2;maxZ = 3;[cc, hh] = contourf('v6', x, y, z, [minZ maxZ]); % Must use version 6
for iContour = 1:length(hh) % Obtain the x and y location of the region's outer edges
% Does not account for cutouts inside the region
if get(hh(iContour), 'cdata') == minZ xOutline = get(hh(iContour), 'xdata'); yOutline = get(hh(iContour), 'ydata'); % Find the points inside the region
isInside = inpolygon(x, y, xOutline, yOutline); endenddelete(hh); % Get rid of contours
Best Answer