Minimum value within contour
25 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposta accettata
Voss
il 4 Feb 2022
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);
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Contour Plots in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!