SCATTER PLOT DIFFERENT COLOURS

4 visualizzazioni (ultimi 30 giorni)
diala yazbeck
diala yazbeck il 23 Feb 2021
Commentato: Just Manuel il 2 Mar 2021
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.

Risposta accettata

Just Manuel
Just Manuel il 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 Commento
Just Manuel
Just Manuel il 2 Mar 2021
Please accept the answer, if it was of use to you.
Cheers
Manuel

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Colormaps in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by