How to locate the x and y co-ordinate of minimum value from a contour plot automatically ?
20 次查看(过去 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.
0 个评论
采纳的回答
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
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 Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!