findpeaksを使って検出されたピークのX値をプロットに加えたい。 I want to add the X values of the peaks on the figure.
61 ビュー (過去 30 日間)
古いコメントを表示
実験で得られたスペクトルのピーク位置をfindpeaksを使って見つけたはいいものの、そのピークのX値をプロットのマーカーに表示させたいのですが可能でしょうか?
Would you tell me how to add the X values of the peaks on the figure?

0 件のコメント
回答 (1 件)
Hernia Baby
2022 年 11 月 4 日
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 件のコメント
Atsushi Ueno
2022 年 11 月 5 日
上記の例にもある様に、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)ずらす
参考
カテゴリ
Help Center および File Exchange で 記述統計 についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!