Hello everybody. I’m using the function “controlchart” to analyze something like the data in the picture, however I was wondering how to use the ‘’findpeaks’’ function to identify the peaks in the red circles and also the width of those peaks. Apparently the ‘’findpeaks’’ function doesn’t work properly in this case, it is possible to use both functions in one chart?. Thank you.

댓글 수: 1

Mathieu NOE
Mathieu NOE 2021년 4월 13일
hello
we could probably better help you if you share a code and data
tx

댓글을 달려면 로그인하십시오.

 채택된 답변

Star Strider
Star Strider 2021년 4월 13일

0 개 추천

That is going to be something of a challenge, however it is possible.
Using an example from the controlchart documentation:
load parts
st = controlchart(runout,'charttype',{'xbar' 'r'});
Ax = gca; % Axis Handle
Kids = Ax.Children; % Axis ‘Children’
x = Kids(4).XData; % Choose Desired Variable, Get ‘XData’
y = Kids(4).YData; % Choose Desired Variable, Get ‘YData’
[pks,locs] = findpeaks(y, 'MinPeakProminence',0.5); % Peaks With Desired Characteristics
figure
plot(x, y)
hold on
plot(x(locs), y(locs), '^r')
hold off
grid
That should work, although it will likely be necessary to experiment with it to get the correct variable and the desired peak characteristics.

댓글 수: 5

Fercho_Sala
Fercho_Sala 2021년 4월 14일
편집: Fercho_Sala 2021년 4월 14일
@Star Strider , @Mathieu NOE ok, according to my question here is the code for the controlchart I have done, however is not possible to generate the peaks inside this plot, based on the curve showed before..
ax9=subplot(1,3,3);
load parts;
st2 = controlchart(MATRIX1,VECTOR1,'Parent',ax9);
ax9.YGrid = 'on';
ax9.XGrid = 'on';
ax9.Children(1).Color = 'w';
ax9.Children(2).Color = 'w';
%%%tile and labels
title('Power [dB]');
ax9.XAxis.FontSize = 7
xlabel('altitude/km','FontSize',11,'FontName','Arial','color','default');
ylabel('Power dB for a LT 2.5h (7:30 - 10:00)','FontSize',11,'color','default');
xlim 'manual'
xlim(ax9,[95 151]);
ytickformat('%g dB');
ax9.XDir = 'reverse';
ax9.YAxisLocation = 'right';
camroll(-90);
legend('off');
hold;
Star Strider
Star Strider 2021년 4월 14일
@Fernando Salamanca Guerrero — Did you try the code I posted with your data?
I cannot attempt to provide any specific code or guidance without the data, since this is obviously specific to the data.
Fercho_Sala
Fercho_Sala 2021년 4월 14일
편집: Fercho_Sala 2021년 4월 14일
yes @Star Strider , your code works so good it overlaps the picks in the second chart showing the peaks according to the ('MinPeakProminence',0.5 ) paramenter, however my variables for the case of 'XDATA' is something like (XDATA(:,151)) it's a matrix , and apparently this doesn't work properly . :) , in your code it will be something like this:
load parts
st = controlchart(XDATA,y,'charttype',{'xbar' 'r'});
Ax = gca;
Kids = Ax.Children;
x = Kids(4).(y);
y = Kids(4).(XDATA(:,151));
[pks2,locs] = findpeaks(XDATA(:,151),y,'MinPeakProminence',0.5);
hold;
plot(XDATA(:,151), y)
hold on
plot((XDATA(:,151)(locs), y(locs), '^r')
hold off
grid
plot((XDATA(locs,151), y(locs), '^r')
perhaps ?
Star Strider
Star Strider 2021년 4월 14일
@Walter Roberson — Thank you!
@Fernando Salamanca Guerrero — I cannot comment on how well my code works with your data. It may be necessary to change the code to work correctly with it, since it may have different characteristics from the characteristics of the data in the example code from the documentation that I used. I cannot help you with that because I do not have the data you are using, or your controlchart call. If you provide those, I can do more than guess as to what the correct approach would be.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Fercho_Sala
Fercho_Sala 2021년 4월 15일
편집: Fercho_Sala 2021년 4월 15일

0 개 추천

@Star Strider Here is the part of the code with the issue, it has been a bit difficult to identify the peaks in the 'controlchart' plot, so for that reason, I generated another plot for the 'findpeaks' function. However the idea is to mix the both functions in just one chart, overlapping by the 'findpeaks' results on the 'controlchart'. Tthe dataset is attached.
ax9=subplot(1,2,1);
load parts;
st2 = controlchart(pws1,y,'Parent',ax9);
ax9.YGrid = 'on';
ax9.XGrid = 'on';
ax9.Children(1).Color = 'w';
ax9.Children(2).Color = 'w';
%%%tile and labels
title('Power [dB]');
ax9.XAxis.FontSize = 7
xlabel('altitude/km','FontSize',11,'FontName','Arial','color','default');
ylabel('Power dB for a LT 2.5h (7:30 - 10:00)','FontSize',11,'color','default');
xlim 'manual'
xlim(ax9,[95 151]);
ytickformat('%g dB');
ax9.XDir = 'reverse';
ax9.YAxisLocation = 'right';
camroll(-90);
legend('off');
%2.5h (7:30 - 10:00)
ax11=subplot(1,2,2);
load parts;
[pks,locs,widths2,proms2] = findpeaks(pws1(:,151),y,'MinPeakHeight',30);
findpeaks(pws1(:,151),y,'Annotate','extents','WidthReference','halfprom');
text(locs+1,pks,num2str((1:numel(pks))'));
legend('Filtered Data','Peak','Prominence','Width');
ax11.YAxisLocation = 'right';
ax11.XDir = 'reverse';
ax11.XGrid = 'on';
ax11.YGrid = 'off';
title ('Layering (7:30 - 10:00)');
ylabel('Layering identification','FontSize',11,'FontName','Arial','color','default');
xlabel('Altitude/km','FontSize',11,'color','default');
yticklabels('');
xlim(ax11,[75 95]);
ylim(ax11,[10.5 36]);
camroll(-90);
%number of peaks found
numberpks1 =(findpeaks(pws1(:,151),y,'MinPeakHeight',30));
numberpks2 =(findpeaks(pws2(:,151),y,'MinPeakHeight',30));

댓글 수: 3

I was thinking of something like this —
ax9=subplot(1,2,1);
% load parts;
st2 = controlchart(pws1,y,'Parent',ax9);
ax9.YGrid = 'on';
ax9.XGrid = 'on';
ax9.Children(1).Color = 'w';
ax9.Children(2).Color = 'w';
Kids = ax9.Children(4);
xcc = Kids.XData;
ycc = Kids.YData;
[pks,locs] = findpeaks(ycc, 'MinPeakProminence',1);
figure(9)
plot(xcc, ycc)
hold on
plot(xcc(locs), ycc(locs), '^r')
hold off
grid
xlim([min(xcc) max(xcc)])
ylim([min(ylim) max(ylim)+4])
title('Points Plotted On Control Chart')
xlabel('X Vector')
ylabel('Y Vector')
legend('Points','Peaks', 'Location','best')
text(xcc(locs), ycc(locs), compose('(%3d, %.2f) \\rightarrow ', [xcc(locs); pks].'), 'Horiz','right', 'Vert','middle', 'Rotation',-45)
producing this plot —
Experiment to get different results. (I had to use return after that code to get it to plot correctly, since it does not automatically open a new figure window, for some reason.)
Fercho_Sala
Fercho_Sala 2021년 4월 15일
@Star Strider thanks, lets's say this is the best way to do it. :)
Star Strider
Star Strider 2021년 4월 15일
As always, my pleasure!
I definitely agree!

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Statistics and Linear Algebra에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

2021년 4월 13일

댓글:

2021년 4월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by