필터 지우기
필터 지우기

K-means, nice graphics

조회 수: 2 (최근 30일)
Bran
Bran 2015년 7월 3일
답변: Mike Garrity 2015년 7월 6일
I have been carrying out some K-means clustering on my data. I would like to graphically display my findings. I have marked the center of mass of my clusters. I would like now to graphically map out the variation of the points in relation to the center but I am not sure how to do this well. I would like it to look nice graphically. I tried to trace out a circle which was proportional with the variation of the points but it wasnt nice graphically, plus my data sits much like an ellipsoid. Does Matlab have a nice graphical feature to do what I want

답변 (1개)

Mike Garrity
Mike Garrity 2015년 7월 6일
What form do you have your variations in?
If your ellipses are axis aligned, then you can use the rectangle command. So if you've got a centroid and width and height, then you can do this:
rng default
centroid = 10*rand(1,2);
width = rand;
height = rand;
rectangle('Position',[centroid(1)-width/2, centroid(2)-height/2, width, height], ...
'Curvature',[1 1])
If they're not axis aligned, then you need to draw the ellipse yourself, but it's not that difficult. Consider the same case, but instead of width and height, we have two basis vectors at 90 degrees to each other.
ang = 2*pi*rand;
r1 = rand;
v1 = [r1*cos(ang), r1*sin(ang)];
r2 = rand;
v2 = [r2*cos(ang+pi/2), r2*sin(ang+pi/2)];
Then we can use the parametric equation for the ellipse to draw it like so:
t = linspace(0,2*pi,50);
plot(centroid(1)+v1(1)*cos(t)+v2(1)*sin(t), ...
centroid(2)+v1(2)*cos(t)+v2(2)*sin(t))
This approach also works for the axis aligned case. You just need to make v1 and v2 look like this:
v1 = [width/2, 0];
v2 = [0, height/2];
Does that make sense?

카테고리

Help CenterFile Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by