findpeaksを​使って検出されたピー​クのX値をプロットに​加えたい。 I want to add the X values of the peaks on the figure.

60 Ansichten (letzte 30 Tage)
SHIMIZU SHUNSUKE
SHIMIZU SHUNSUKE am 4 Nov. 2022
Kommentiert: Hernia Baby am 6 Nov. 2022
実験で得られたスペクトルのピーク位置をfindpeaksを使って見つけたはいいものの、そのピークのX値をプロットのマーカーに表示させたいのですが可能でしょうか?
Would you tell me how to add the X values of the peaks on the figure?

Antworten (1)

Hernia Baby
Hernia Baby am 4 Nov. 2022
text関数をご使用ください
data = [25 8 15 5 6 10 10 3 1 20 7];
plot(data)
ここで座標を取得します
[pks,locs] = findpeaks(data);
テキストをプロットしていきます
hold on
for ii = 1:length(locs)
text(locs(ii),pks(ii),num2str(locs(ii)))
end
  3 Kommentare
Atsushi Ueno
Atsushi Ueno am 5 Nov. 2022
上記の例にもある様に、findpeaks関数が持つ描画機能(主な違いは▼の表示)を使う事を提案します。その場合同じfindpeaks関数を2度実行する必要があります。また、text関数の引数を列ベクトルにすればforループを回す必要がありません。
data = [25 8 15 5 6 10 10 3 1 20 7];
[pks,locs] = findpeaks(data); % 一回目(ピーク値pksとそのインデックスlocsを得る為)
findpeaks(data); % 二回目(グラフを描画する為)
text(locs+.2, pks, num2str(locs')); % 表示位置をちょっと(0.2)ずらす
Hernia Baby
Hernia Baby am 6 Nov. 2022
確かに列ベクトルにすれば for ループかけなくていいですね。
補足ありがとうございます。

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

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

Start Hunting!