Finding coordinates in a plot

3 ビュー (過去 30 日間)
Tanmay Singh
Tanmay Singh 2021 年 8 月 21 日
コメント済み: Star Strider 2021 年 8 月 22 日
I have to find halfwidth of a curve I have plotted for this I need to find half of maximum value in the plot and their corresponding coordinates.How do I find it?
  2 件のコメント
darova
darova 2021 年 8 月 21 日
Where is the curve?
Tanmay Singh
Tanmay Singh 2021 年 8 月 21 日

サインインしてコメントする。

採用された回答

Star Strider
Star Strider 2021 年 8 月 21 日
I hope this is not homework!
x = linspace(-5000, 5000, 250);
y = [7.5; 1.9; 0.9] .* exp(-(0.001*[1; 0.85; 0.6] * x).^2);
[ymx,idx] = max(y,[],2);
hafmax = ymx/2;
for k = 1:numel(hafmax)
idxrng1 = find(y(k,1:idx(k))<hafmax(k), 1, 'last');
idxrng2 = find(y(k,idx(k):numel(x))<hafmax(k),1,'first')+idx(k);
xm(k,1) = interp1(y(k,idxrng1+(-3:3)), x(idxrng1+(-3:3)), hafmax(k));
xm(k,2) = interp1(y(k,idxrng2+(-3:3)), x(idxrng2+(-3:3)), hafmax(k));
end
format short g
xm
xm = 3×2
-832.87 832.87 -979.71 979.71 -1387.7 1387.7
format short
figure
plot(x, y)
hold on
for k = 1:numel(hafmax)
plot([xm(k,1) xm(k,2)], [1 1]*hafmax(k), '-k', 'LineWidth',1.5)
end
hold off
grid
xlim([-1 1]*2000)
Make appropriate changes with respect to your data.
.
  2 件のコメント
Tanmay Singh
Tanmay Singh 2021 年 8 月 22 日
Thankyou..!
Star Strider
Star Strider 2021 年 8 月 22 日
As always, my pleasure!
.

サインインしてコメントする。

その他の回答 (1 件)

darova
darova 2021 年 8 月 21 日
Use polyxpoly
x1 = 0:.1:pi; % first curve
y1 = sin(x1);
x2 = [0 pi]; % straight line for findinf intersection
y2 = [1 1]*max(y1)/2;
[xc,yc] = polyxpoly(x1,y1,x2,y2);
plot(xc,yc,'.r')
line(x1,y1)
line(x2,y2)
  1 件のコメント
Tanmay Singh
Tanmay Singh 2021 年 8 月 22 日
thanks alot..!

サインインしてコメントする。

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by