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

1 回表示 (過去 30 日間)
Phudit Kanittasut
Phudit Kanittasut 2021 年 3 月 28 日
コメント済み: Phudit Kanittasut 2021 年 4 月 2 日
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
Phudit Kanittasut 2021 年 4 月 2 日
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 Center および File ExchangeDescriptive Statistics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by