How can I plot 2 data in 1 graph and find common peak

4 次查看(过去 30 天)
How can I plot 2 data in 1 graph and find common peak
Common peak is a peak that appear at the same X coordinate but have different Y value
pure_brain = readmatrix('Pure Brain Spectra.csv');
[pks,locs] = findpeaks(pure_brain(:,2));
x = 1:size(pure_brain,1);
Y = pure_brain(locs(Lv),2);
Y = Y .* 100/max(Y);
[pks_min,pks_max] = bounds(pks) % Minimum & Maximum Values Of ‘pks’
figure
Lv = pure_brain(locs,2)>1E+4; % Set Threshold = 1E+4
% Lv = pure_brain(locs,2)>1; % Set Threshold = 1
%plot(x(locs(Lv)), pure_brain(locs(Lv),2), '.r')
plot(x(locs(Lv)), Y, '.r')
grid
title('Pure brain peak');
%AB=unique(pks);
%YB1=AB(end); %1Y
%YB2=AB(end-1); %2Y
%YB3=AB(end-2); %3Y
%EB1=find(pks==YB1);
%XB1=locs(EB1);
%EB2=find(pks==YB2);
%XB2=locs(EB2);
%EB3=find(pks==YB3);
%XB3=locs(EB3);
%SYB = [ YB1 YB2 YB3 ];
%SXB = [ XB1 XB2 XB3 ];

采纳的回答

Pavan Guntha
Pavan Guntha 2021-3-31
Hi Phudit,
You can refer to documentation of hold function to plot 2 different plots on same figure. To calculate the common peak, you can first find the common indices where a peak exists for both the datasets and then find the value of the peaks occured at those indices. The following code illustrates this idea:
pure_brain = readmatrix('Pure Brain Spectra.csv');
[pks,locsBr] = findpeaks(pure_brain(:,2));
LvBrain = pure_brain(locsBr,2)>1E+4; % Set Threshold = 1E+4
xBrain = 1:size(pure_brain,1);
YBrain = pure_brain(locsBr(LvBrain),2);
YBrain = YBrain .* 100/max(YBrain);
[pks_min,pks_max] = bounds(pks); % Minimum & Maximum Values Of pks
figure
pure_Liver = readmatrix('Pure Liver Spectra.csv');
[pks,locsLiv] = findpeaks(pure_Liver(:,2));
LvLiver = pure_Liver(locsLiv,2)>1E+4; % Set Threshold = 1E+4
xLiver = 1:size(pure_Liver,1);
YLiver = pure_Liver(locsLiv(LvLiver),2);
YLiver = YLiver .* 100/max(YLiver);
plot(xBrain(locsLiv(LvBrain)), YBrain, '.r')
hold on
plot(xLiver(locsLiv(LvLiver)), YLiver, '*b')
hold off
grid
% To find common peaks considering the threshold of 1E+4:
lB = locsBr(LvBrain);
lL = locsLiv(LvLiver);
s = max(length(lB), length(lL));
locsLivNew = [lL; false(s-length(lL),1)];
locsBrNew = [lB; false(s-length(lB),1)];
common = locsLivNew == locsBrNew; % Find the common location of peaks
Hope this helps!
  1 个评论
Phudit Kanittasut
Your answer is so helpful ,thank you , but I have one question I open common and I cant get the location of the common peak.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Preprocessing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by