SCATTER PLOT DIFFERENT COLOURS
2 views (last 30 days)
Show older comments
hello!
so i have a table with 5 columns.
column 1 has values 1-12 (but this can vary depending on the data set), column 2 is time, column 3 is either 1 or 0 (right/left), and column 4 and 5 are x and y co-ordinates respectively.
I am trying to graph all of column 4 and 5 against column 3. all is well.
HOWEVER i need the colour of the graph to be blue if value in column 3 = 1 and red if = 0.
so the overall graph needs to look like this.
the script for this code is as follows
gscatter(COP_num(:,4), COP_num(:,5), COP_num(:,3), 'brbrbrg', '.')
legend({'right foot (blue)', 'left foot (red)', 'i dont know'})
title('Centre of Pressure data exported from GaitRite')
xlabel('X COP values'); ylabel('Y COP values');
set(gca, 'YDir', 'reverse');
hold
i NEED to try get it so that it is automatic and can apply to anything.
if the data is not 0 or 1 i want it to be green.
0 Comments
Accepted Answer
Just Manuel
on 23 Feb 2021
Split your x/y data into two sets; one for right, one for left, then plot those.
x_left = COP_num(COP_num(:,3) == 0,4);
y_left = COP_num(COP_num(:,3) == 0,5);
x_right = COP_num(COP_num(:,3) == 1,4);
y_right = COP_num(COP_num(:,3) == 1,5);
hold on
scatter(x_left,y_left);
scatter(x_right,y_right);
Cheers
Manuel
1 Comment
Just Manuel
on 2 Mar 2021
More Answers (0)
See Also
Categories
Find more on Colormaps 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!