SCATTER PLOT DIFFERENT COLOURS

4 ビュー (過去 30 日間)
diala yazbeck
diala yazbeck 2021 年 2 月 23 日
コメント済み: Just Manuel 2021 年 3 月 2 日
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
  1 件のコメント
Just Manuel
Just Manuel 2021 年 3 月 2 日
Please accept the answer, if it was of use to you.
Cheers
Manuel

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeColormaps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by