How to label plot having peaks in matlab

一个人想着一个人 提交于 2019-12-11 13:47:26

问题


I'm trying to label my XRD data which have peaks, and I want to label it from my array of data:

  peak label  
    ab
    ac
    ad
    cb
    bb
    ba

See picture below

I also want those labels to be vertically aligned on the top of the peaks. I tried the findpeaks function but it doesn't work.


回答1:


Try this (but you need to have a Signal Processing Toobox):

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

As you have the index peaks, you can labeled as you want.



来源:https://stackoverflow.com/questions/28712464/how-to-label-plot-having-peaks-in-matlab

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!