How to locate the x and y co-ordinate of minimum value from a contour plot automatically ?

38 次查看(过去 30 天)
I am trying to plot a contour and find it's x and y co-ordinate of the minimum value from the contour plot. Here is a sample code.
clear variables
format long
close all
clc
a = 10;
b = 20;
c_dom = 1:10;
d_dom = 11:20;
L_c_dom = length(c_dom);
L_d_dom = length(d_dom);
e = zeros(L_c_dom, L_d_dom);
for j_c = 1:L_c_dom
for j_d = 1:L_d_dom
c = c_dom(j_c);
d = d_dom(j_d);
e(j_c, j_d) = a*b*c*d;
end
end
[x, y] = meshgrid(c_dom, d_dom);
[C, h] = contour(x, y, e);
Above figure is the contour plot. Now, I need to locate the position (x and y co-ordinates) of it's minimum value automatically. Since this is a sample code so I know that the first value of variable 'c_dom' and 'd_dom' are the x and y co-odrinates. But in reality my actual code is a bit complicated and the contours are bunch of concentric circles. I checked online but I am just getting the use of min() command to get the minimum value but I didn't find any procedure to locate it's position (x and y co-ordinates). I did another technique where I found out the minimum value of the contour and plotted the value and highlighted it. After clicking at that point I can get x and y co-ordinates from the plot itself. But unfortunately it's a very tedius job and if I had to do a parametric study where my variable 'a' and 'b' are also a vector, then it is a very lengthy process. So, I need to find a way to locate x and y co-ordinates automatically. Any help will be greatly appreciated.

采纳的回答

Turlough Hughes
Turlough Hughes 2021-8-22
编辑:Turlough Hughes 2021-8-22
Try:
[min_e,index] = min(e,[],'all','linear');
x_min = x(index);
y_min = y(index);
hold on, plot(x_min,y_min,'ok','MarkerFaceColor','k');
This gives the location of x and y (the index) corresponding to the minimum in e.
  3 个评论
gaurav pandey
gaurav pandey 2023-9-13
Hello,
Thanks for your input and it works for me.
However, my contour has three minima. Could you please help me to locate these three lowest minima and their corresponding location of x and y.
Thank you in advance

请先登录,再进行评论。

更多回答(0 个)

类别

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

产品


版本

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by