How to plot data points in different colors depending on condition?

51 views (last 30 days)
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.

Accepted Answer

TADA
TADA on 15 Feb 2019
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));

More Answers (0)

Categories

Find more on Visual Exploration in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!