pos = find(y==1);
neg = find(y==0);
plot(X(pos, 1), X(pos, 2), "k+", "LineWidth", 2, 'MarkerSize', 7);
plot(X(neg, 1), X(neg, 2), "ko", "MarkerFaceColor", 'y', 'MarkerSize', 7);
I understand that find function gives us the index of the data where y==1 and y==0. But I am not sure what X(pos,1) and X(pos,2) do in the function below. Can someone explain how this plot function works?
pos
and neg
are vectors with indices where the condition y==1
(respectively y==0) is fulfiled. y
seems to be a vector with length n, X
seems to be a nx2 Matrix. X(pos,1)
are all elements of the first column of X
at rows where the condition y==1
is met.
y = [ 2 3 1 4 0 1 2 6 0 4]
X = [55 19;54 96;19 85;74 81;94 34;82 80;79 92;57 36;70 81;69 4]
X(find(y==1), 1)
which gives
ans =
19
82
Note that find isn't needed here,
X(y==1, 1)
would be sufficient
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With