フィルターのクリア

Legend doesn't show correct colors

1 回表示 (過去 30 日間)
Mandana Fröhlich
Mandana Fröhlich 2021 年 4 月 19 日
コメント済み: Mandana Fröhlich 2021 年 4 月 19 日
hi, i'm trying to plot my erp and the legend doesn't show the correct colors.
the code:
figure;
for i_chan = 4 %here specify the index of the channel
shadedErrorBar(EEG_EC_epochrej.times, EKP_avg_EC(i_chan,:), (SD_EC(i_chan,:)/sqrt(nsamples)), 'g',1);
hold on
shadedErrorBar(EEG_EC_epochrej.times, EKP_avg_EO(i_chan,:), (SD_EO(i_chan,:)/sqrt(nsamples)), 'b',1);
shadedErrorBar(EEG_EC_epochrej.times, EKP_avg_nonREM(i_chan,:), (SD_nonREM(i_chan,:)/sqrt(nsamples)), 'm',1);
shadedErrorBar(EEG_EC_epochrej.times, EKP_avg_REM(i_chan,:), (SD_REM(i_chan,:)/sqrt(nsamples)), 'r',1);
legend({'EC', 'EO', 'nonREM', 'REM'}, 'Location', 'southwest')
xlabel('Time [ms]')
ylabel('Amp [muV]');
xlim([-100 650]) %adjust limit based on your epoch length
title(EEG_EC_epochrej.chanlocs(chan(i_chan)).labels)
end
Thanks for the help

採用された回答

Walter Roberson
Walter Roberson 2021 年 4 月 19 日
Your code assumes that shadedErrorBar creates exactly one graphics object per call. However if you are using https://www.mathworks.com/matlabcentral/fileexchange/26311-raacampbell-shadederrorbar then shadedErrorBar creates:
  • one line for each column of y (or one line if y is a row vector)
  • one patch object for the shading
  • two edge lines
For a total of 4 graphics objects for your case (where you are passing in one row per call)
shadedErrorBar returns a struct with three fields. If you want the lines to be marked in the legend, then extract the field named mainline from the return from each of the calls. If you want the shading to be marked in the legend, then extract the field named patch from the return from each of the calls. Then pass the vector of graphic handles as the first paramter to legend(), before the legend strings.
  1 件のコメント
Mandana Fröhlich
Mandana Fröhlich 2021 年 4 月 19 日
thanks a lot!! i managed

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLegend についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by