如何在 matlab 中标记具有峰值的图

How to label plot having peaks in matlab

我正在尝试标记我的具有峰的 XRD 数据,我想从我的数据数组中标记它:

  peak label  
    ab
    ac
    ad
    cb
    bb
    ba

见下图

我还希望这些标签在峰顶垂直对齐。 我尝试了 findpeaks 功能,但它不起作用。

试试这个(但你需要有一个信号处理工具箱):

x = [1 2 3 4 5 6 7 8 9] 
y = [1 4 2 7 3 9 5 10 2]
[peak, peakId] = findpeaks(y); %find peaks in your serie
figure(1) 
plot(x, y)
lbalph=('a':'z').'
lb=strcat(Alphabet(1),lbalph(1:length(peak))) %Create a label matrix
lb = num2cell(lb,2) % Convert to cell array
lbid = 1:length(lb)
text(x(peakId), peak, lb(lbid),'Rotation',90) % label the peak with your lb matrix

有了索引峰,您可以根据需要进行标记。