trying to make many subjects the same color in graph

1 回表示 (過去 30 日間)
nines
nines 2020 年 1 月 6 日
回答済み: Meg Noah 2020 年 1 月 7 日
Hello!
I am trying to make groups of subjects on a graph, and I am trying to define the subject and give it a certain color. there was a code online that said that said that something like my code below should work, but i am still getting errors. does anyone have any ideas? Thanks times a billion!
figure;
% plot(f, allspectrums_cortex_young, 'r');
% plot(f, allspectrums_ventricle_young, 'y');
% plot(f, allspectrums_cortex_elderly, 'b')
% plot(f, allspectrums_ventricle_elderly, 'g')
l1 = plot(f, allspectrums_cortex_young, 'r');
hold on
l2 = plot(f, allspectrums_ventricle_young, 'y');
l3 = plot(f, allspectrums_cortex_elderly, 'b')
l4 = plot(f, allspectrums_ventricle_elderly, 'g')
legend([l1, l2, l3, l4], {'ventricle cortex', 'ventricle young', 'ventricle elderly', 'cortex elderly'});
hold off
xlabel('Frequency (in hertz)');
ylabel('Power');
title('Young vs. Elderly Power - 4th Ventricle and Cortex')

採用された回答

Meg Noah
Meg Noah 2020 年 1 月 7 日
With some fake data, this works:
% fake data
f = -pi:0.01:pi;
allspectrums_cortex_young = sin(2.*f + pi/3) + 0.05*rand(size(f));
allspectrums_ventricle_young = sin(3.*f + pi/2) + 0.05*rand(size(f));
allspectrums_cortex_elderly = sin(2.5.*f + 0) + 0.05*rand(size(f));
allspectrums_ventricle_elderly = sin(0.75.*f + pi/6) + 0.05*rand(size(f));
% code
figure;
l1 = plot(f, allspectrums_cortex_young, 'r','DisplayName','ventricle cortex');
hold on
l2 = plot(f, allspectrums_ventricle_young, 'color', [0.8 0.7 0],'DisplayName','ventricle young');
l3 = plot(f, allspectrums_cortex_elderly, 'b','DisplayName','ventricle elderly');
l4 = plot(f, allspectrums_ventricle_elderly, 'color', [0 0.75 0],'DisplayName','cortex elderly');
legend('location','best');
hold off
xlabel('Frequency (in hertz)');
ylabel('Power');
title('Young vs. Elderly Power - 4th Ventricle and Cortex')

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBehavior and Psychophysics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by