SCATTER PLOT DIFFERENT COLOURS

4 次查看(过去 30 天)
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.

采纳的回答

Just Manuel
Just Manuel 2021-2-23
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by