Trouble with findpeaks - 14 EEG signals and peaks on same plot - different colors

조회 수: 4 (최근 30일)
Hi,
I am trying to plot 14 EEG signals and their peaks on the same plot, but I am having trouble getting all of the findpeaks to have the triangle symbol in the same color as the EEG signal. Rather than have matching colors, and have all findpeaks have the triangle symbol, I keep getting a legend like this:
Is there a way I can get them to match colorwise and to make all of the findpeaks have the triangle symbol? I've attached a zip folder containing my matlab code and the csv file (this figure's code starts at line 36).
Also, I know it won't be easily legible with all 14 signals and peaks on the plot. I plan to add and remove certain signals as I need to, but I'd like to have all 14 signals on the same plot to start with.
Secondary Request:
If possible, I'd like to have the peaks on the right column of the legend and the EEG signals on the left column. Also, is there a way I can title a legend column?
Thank you for your help!
  댓글 수: 3
Christina Diersing
Christina Diersing 2021년 7월 13일
Thank you again for your help!
I got the findpeaks to work now and the plot looks exactly how I wanted it to.
I am trying to do what you suggested for the variable names, but I am having some difficulty. (I have never used table properties before yesterday and, though I read through the documentation and tried several different lines of code to try to rename the variable names, I am still having trouble.) Basically, I am trying to write a for loop like you had on my other question, but to replace the repetitive lines of code at the beginning of this excerpt:
AF3=T.EEG_AF3; F7=T.EEG_F7;
F3=T.EEG_F3; FC5=T.EEG_FC5;
T7=T.EEG_T7; P7=T.EEG_P7;
O1=T.EEG_O1; O2=T.EEG_O2;
P8=T.EEG_P8; T8=T.EEG_T8;
FC6=T.EEG_FC6; F4=T.EEG_F4;
F8=T.EEG_F8; AF4=T.EEG_AF4;
for j=2:width(T)
NewVarNames(j)=extractAfter(T.Properties.VariableNames(j),'_');
%T.Properties.VariableNames(j)=extractAfter(T.Properties.VariableNames(j),'_');
end
T.Properties.VariableNames=NewVarNames;
It's likely a stupid error on my part, but I have spent at least 3 hours trying to get it to work. Could you help with this please?
dpb
dpb 2021년 7월 14일
I did not see the above plaintive cry in the wilderness until now...sorry!
>> tTry.Properties.VariableNames(2:end)=extractAfter(tTry.Properties.VariableNames(2:end),'_');
>> head(tTry)
ans =
8×15 table
Timestamp AF3 F7 F3 FC5 T7 P7 O1 O2 P8 T8 FC6 F4 F8 AF4
_____________ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______ _______
1622835751.19 4260.38 4267.69 4316.03 4305.51 4340.00 4278.46 4278.97 4279.62 4235.26 4184.87 4456.67 4401.79 4343.59 4387.05
1622835751.20 4264.87 4261.92 4311.79 4308.59 4338.97 4280.26 4279.74 4276.79 4232.18 4184.74 4442.69 4401.54 4334.23 4380.77
1622835751.20 4266.28 4272.05 4316.41 4312.56 4340.51 4280.77 4286.41 4275.77 4229.62 4178.33 4438.21 4405.38 4325.26 4381.03
1622835751.21 4262.82 4274.74 4319.74 4311.28 4342.44 4280.77 4288.21 4281.41 4242.82 4181.28 4444.87 4407.82 4330.64 4389.49
1622835751.22 4266.15 4267.56 4318.85 4308.08 4332.56 4279.23 4282.31 4285.64 4248.59 4186.03 4448.72 4404.23 4333.72 4392.31
1622835751.23 4266.92 4267.95 4317.69 4298.33 4322.95 4277.95 4275.77 4275.13 4235.00 4179.87 4440.77 4398.97 4326.28 4386.92
1622835751.24 4255.26 4269.49 4309.87 4293.21 4328.08 4278.08 4270.13 4265.38 4229.62 4177.95 4425.51 4394.49 4325.26 4383.33
1622835751.24 4254.87 4265.13 4306.54 4303.33 4336.54 4280.13 4267.82 4272.44 4242.95 4184.74 4431.79 4397.05 4328.21 4382.18
>>

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

채택된 답변

dpb
dpb 2021년 7월 13일
편집: dpb 2021년 7월 14일
T.Timestamp=T.Timestamp-T.Timestamp(1); % 1622835751.18846;
varlist={'AF3','F7','F3','FC5','T7','P7','O1','O2','P8','T8','FC6','F4','F8','AF4'};
%% Reg Plot - all EEG Signals and peaks on same plot
hF1=figure('Name', 'EEG Signals and Peaks - Same Plot');
newcolors={'#0072BD','#D95319','#EDB120','#7E2F8E','#77AC30','#4DBEEE','#A2142F', ...
'#FF0000','#00FF00','#0000FF','#00FFFF','#FF00FF','#FFFF00','#000000'};
colororder(newcolors);
grid on; hold on;
for i=1:numel(varlist)
ix=find(matches(extractAfter(tTry.Properties.VariableNames,'_'),varlist(i))); % get the wanted variable in list order
findpeaks(T{:,ix}, T.Timestamp,'MinPeakProminence',100); % draw the findpeaks plot
end
hAx=gca; hL=hAx.Children; % retrieve handles to lines
hLG=legend([hL(2:2:end);hL(1:2:end)],[varlist strcat(varlist,' Peaks')], 'NumColumns', 2); % write legend in desired order
hLG.FontSize=7; hLG.Location='best';
title('Try 4 EEG Test');
xlabel('Timestamp (s)');
ylabel('EEG Value (uV)');
fig1.WindowState = 'maximize';
results in
where just a little frontend effort lets one reduce some 14 calls to a loop of 4 lines that can be arranged in whatever order is later desired if ever want to change simply by reordering one array of names as well as elminate the difference in colors owing to extra uneeded call to plot.
The legend is rearranged as desired simply by reordering the order of the handles passed; like everything else in MATLAB, the default order is by column and findpeaks puts the peaks line first where the desire is to have the solid line first instead. One could do it by rearranging the handle array order; I just took the expedient of passing the two sets in the desired order to legend directly.
  댓글 수: 1
dpb
dpb 2021년 7월 14일
"The legend is rearranged as desired simply by reordering the order of the handles passed;"
Since the channel is given in the first column, if it were me I think I'd just use 'Peaks' for the second column of the legend to reduce the clutter slightly instead of duplicating the channel ID....

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 EEG/MEG/ECoG에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by