Minimum value within contour
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Konvictus177
el 4 de Feb. de 2022
Respondida: Voss
el 4 de Feb. de 2022
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 comentarios
Respuesta aceptada
Voss
el 4 de Feb. de 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 comentarios
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!