How to locate the x and y co-ordinate of minimum value from a contour plot automatically ?
18 ビュー (過去 30 日間)
古いコメントを表示
SOMYA RANJAN PATRO
2021 年 8 月 22 日
コメント済み: gaurav pandey
2023 年 9 月 13 日
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!