MATLAB Answers

How can I plot data in one matrix and color the data differently using data from another matrix?

조회 수: 1(최근 30일)
Nora Khaled
Nora Khaled 2 May 2019
Commented: Nora Khaled 2 May 2019
Hi !
I have a matrix with "data" with size n by 2. this matrix rows contain some value that I want to plot.
and another matrix with size "R" n by k. this matrix contain ones and zero. the sum of each row is one.
the matrix R indicate each row of data follows which colunm out of the k columns.
for example:
data =[1 2; 2 4 ; 3 6;4 7];
R= [0 1 0 0; 0 0 1 0; 0 1 0 0; 1 0 0 0];
now I want to plot the matrix data
but I want the points colours to be diffrent according to which column of R contain the 1.
in the example I will have the 1st data points and the last ones with the same color. and the others are diffrent.
also the number of columns in R = k >= 2 ( but not necessarily 3)
How can I do this ??
thank you.

  댓글 수: 0

로그인 to comment.

답변 수 (1)

KSSV 2 May 2019
data =[1 2; 2 4 ; 3 6;4 7];
R= [0 1 0; 0 0 1; 0 1 0; 1 0 0];
hold on
for i = 1:size(data,1)
Have a look on scatter also.

  댓글 수: 3

Nora Khaled
Nora Khaled 2 May 2019
Thank you for your answer!
but what do I do if R is 2 columns or 4. cause this get me an error that the color must be 3 values.
KSSV 2 May 2019
R must have three color stands for RGB color code.
Nora Khaled
Nora Khaled 2 May 2019
I have matrix R indicating the group the each row of data is in. So, it can be 2,3,4,...
and I want the color of each group of data to be the same.
I did edit the question to make it more clear.
Thank you.

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.

Translated by