Minimum value within contour

17 ビュー (過去 30 日間)
Konvictus177
Konvictus177 2022 年 2 月 4 日
回答済み: Voss 2022 年 2 月 4 日
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 Center および File ExchangeContour Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by