Minimum value within contour

24 次查看(过去 30 天)
Hi,
I would like to find the minimum value within a contour.
Let's say I have the following code that draws contours around all values that are lower than a set threshold. How can I find the minimum value within or for each contour and save it to a variable, list or table?
[X,Y,Z] = peaks(100);
figure(1),hold on
s = surf(X,Y,Z,'Facealpha',0.75,'Edgecolor','none');
view(2);
colorbar('vert');
threshold = -0.3*max(Z,[],'all');
[c,h] = contour(X,Y,Z,[threshold threshold],'-k','Linewidth',5);
hold off

采纳的回答

Voss
Voss 2022-2-4
You can use the information in c along with inpolygon() and logical indexing in Z to do it:
[X,Y,Z] = peaks(100);
figure(1),hold on
s = surf(X,Y,Z,'Facealpha',0.75,'Edgecolor','none');
view(2);
colorbar('vert');
threshold = -0.3*max(Z,[],'all');
[c,h] = contour(X,Y,Z,[threshold threshold],'-k','Linewidth',5);
hold off
Z_min = [];
idx = 1;
N = size(c,2);
while idx < N
pts = c(:,idx+(1:c(2,idx)));
in_region = inpolygon(X,Y,pts(1,:),pts(2,:));
Z_min(end+1) = min(Z(in_region));
text(mean(pts(1,:)),min(pts(2,:)),max(Z(:)), ...
sprintf('Min Z: %f',Z_min(end)), ...
'VerticalAlignment','top', ...
'BackgroundColor','w');
idx = idx+c(2,idx)+1;
end
disp(Z_min);
-6.5419 -3.0474

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Contour Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by