trying to make many subjects the same color in graph

조회 수: 3 (최근 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 CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by