findpeaksを使って検出されたピークのX値をプロットに加えたい。 I want to add the X values of the peaks on the figure.
22 次查看(过去 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!