I have matrix X which is 225 by 6. And vector y which is 225 by 1. y is a binary with values 0 or 1. What I need to accomplish is to plot every column in X with y seperately.
Just a short example For instance:
x1 x2 x3 (x4 -x6)etc y
26 0,01 -1,15 0
25 0,025 1,58 1
20 0,185 2,57 1
I need to plot x1 with y, x2 with y etc... for pos=find(y==1) and neg=find(y==0)
I only accomplished to plot all column with y. But the is not satisfactory because the columns in X have different ranges of values.
*function plotData(X,y)*
pos = find(y==1);
neg = find(y==0);
plot(X(pos,1),X(pos,2),X(pos,3),X(pos,4),X(pos,5),X(pos,6),'kx','MarkerSize',5,'Color','s')
hold on
plot(X(neg,1),X(neg,2),X(neg,3),X(neg,4),X(neg,5),X(neg,6),'ko','MarkerSize',5,'Color','r')
*end*
But this way it plots all columns at once. How can I do it seperately?
Thanks in advance.

댓글 수: 4

José-Luis
José-Luis 2017년 9월 10일
편집: José-Luis 2017년 9월 10일
I don't get it. You already have the logical index:
plot(x(y,:))
hold on
plot(x(~y,:))
What really baffles me is what you expect this plot to show: what is the reason for this indexing?
JacquelineK
JacquelineK 2017년 9월 10일
Hi José,
y is a binary. So I want to plot lets say the FirmSize of my companies with y to see how the values of one x scatters "between" y=0 and y=1.
José-Luis
José-Luis 2017년 9월 10일
편집: José-Luis 2017년 9월 10일
I still don't follow. You won't get a "scatter" unless by pure random luck there's an equal number of zeros and ones in y.
JacquelineK
JacquelineK 2017년 9월 10일
I plotted each x with y now. This is what I got for FirmSize.
It is still not what I imagined, but better than before :)

댓글을 달려면 로그인하십시오.

답변 (1개)

Jose Marques
Jose Marques 2017년 9월 10일

0 개 추천

Hello, Jacqueline Kpognon. Do you want to differents figures? Try this:
pos = find(y==1);
neg = find(y==0);
plot(X(pos,1),X(pos,2),X(pos,3),X(pos,4),X(pos,5),X(pos,6),'kx','MarkerSize',5,'Color','s')
figure();
plot(X(pos,1),X(pos,2),X(pos,3),X(pos,4),X(pos,5),X(pos,6),'ko','MarkerSize',5,'Color','r')

댓글 수: 1

JacquelineK
JacquelineK 2017년 9월 10일
편집: Cedric 2017년 9월 10일
Hello Jose,
I wrote a mistake there. First plot is for x(pos) and second plot is for x(neg).
plot(X(pos,1),X(pos,2),X(pos,3),X(pos,4),X(pos,5),X(pos,6),'kx','MarkerSize',5,'Color','s')
plot(X(neg,1),X(neg,2),X(neg,3),X(neg,4),X(neg,5),X(neg,6),'ko','MarkerSize',5,'Color','r')
I tried your modification. It opens 2 figures. the second one is empty.
I am trying to plot x1 with y==1 and y==0 and then x2 with y==1 and y==0.
I thought a loop would help me get it, but I can't figure it out.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

질문:

2017년 9월 10일

편집:

2017년 9월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by