Mark the peak of a graph

27 ビュー (過去 30 日間)
Brian Hoblin
Brian Hoblin 2016 年 10 月 31 日
コメント済み: Brian Hoblin 2016 年 10 月 31 日
I'm trying to place a marker at the peak power value of a graph but I'm having trouble. This is my code,
[Peak, PeakIdx] = findpeaks(Power);
plot (Resistance,Power)
hold on
grid on
ylabel ('Power (mW)')
xlabel ('Resistance (\Omega)')
title ('Power vs Resistance')
text(Resistance(PeakIdx), Peak, sprintf('Peak = %6.3f (mW)', Peak))
I get "Peak=24.900 (mW)" but I'd like there to be some sort of marker at the exact location of the peak on the graph. I've looked around and found a page that should be answering my question but I must be doing something wrong. On the image below I would like there to be a circle (or something) to more clearly indicate that peak power occurred at 1000 ohms. I can put a couple spaces in to move "Peak..." over (' Peak = %6.3f (mW)', Peak). Any suggestions? Thanks in advance.

採用された回答

KSSV
KSSV 2016 年 10 月 31 日
[Peak, PeakIdx] = findpeaks(Power,Resistance);
findpeaks(power,Resistance)
hold on
grid on
ylabel ('Power (mW)')
xlabel ('Resistance (\Omega)')
title ('Power vs Resistance')
text(Resistance(PeakIdx), Peak, sprintf('Peak = %6.3f (mW)', Peak))
  2 件のコメント
Brian Hoblin
Brian Hoblin 2016 年 10 月 31 日
This comes really close but my "text..." line causes "Index exceeds matrix dimensions". Any idea on how to correct that?
Brian Hoblin
Brian Hoblin 2016 年 10 月 31 日
Ok. I messed around with both suggestions and I was able to get 2 different versions that both satisfy. Sorry I couldn't accept both because both were very helpful. One utilizes a legend and the one I needed to add a 'hold on' to. Thank you for your assistance.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by