How to plot data points in different colors depending on condition?
조회 수: 60 (최근 30일)
이전 댓글 표시
Hello,
I've plotted data points accross 320 trials. Within each trial, there were 2 conditions (for example trials 1-80 were random, and trials 81-160 were sequenced, and so on).
I was able to plot the 320 trials, but I would like to specify which condition each data point was by making them different colors.
How can I go about adding this to my plot? I have a separate string called SRTT.Sequence (320x1) which contains all the conditions per trial if that helps.
f1=figure;
x=1:320;
y=SRTT.RT(1:320);
plot(x,y,'-o')
ylabel('Reaction Time (s)');
xlabel('Trial');
set(gca, 'fontsize' , 16, 'fontweight', 'bold');
set(gca,'XTick',(0:20:320));
Thanks in advance for any suggestions.
댓글 수: 0
채택된 답변
TADA
2019년 2월 15일
you can use the conditions to create logical index masks of your data and plot only the relevant data for each condition:
f1=figure(1);
clf();
hold on;
x=1:320;
% lets say the condition is now a flag containing either 1 or 0, I assume
% it's more complex in your case, but for simplicity's sake lets keep it
% like that: 1=random, 0=sequenced
SRTT.Sequence = [ones(160,1); zeros(160,1)];
SRTT.RT = [rand(1, 160) * 80, 161:320]';
% create masks according to trial condition
randFlags = SRTT.Sequence == 1;
seqFlags = SRTT.Sequence == 0;
y=SRTT.RT(1:320);
plot(x(randFlags),y(randFlags),'-o', 'Color', 'b');
plot(x(seqFlags),y(seqFlags),'-o', 'Color', 'r');
ylabel('Reaction Time (s)');
xlabel('Trial');
set(gca, 'fontsize' , 16, 'fontweight', 'bold');
set(gca,'XTick',(0:20:320));
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Visual Exploration에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!