how show the clusters graphically?
이전 댓글 표시
hi,
I got the indices of clusters of my data. I would like to see the result with drawing. i.e I hope to see the clusters graphically.
can do that?
thanks in advance
답변 (3개)
per isakson
2012년 8월 13일
0 개 추천
... and the statistical toolbox
댓글 수: 3
huda nawaf
2012년 8월 13일
Walter Roberson
2012년 8월 13일
Look at the Description at that link. It describes exactly what each of the parameters means.
Image Analyst
2012년 8월 13일
There are no clusters in that data because your data is uniformly spaced. Or there are 6 clusters with just one point in them, or one big cluster with 6 points. You don't really have aggregation or clumping of any of the points.
Ilya
2012년 8월 13일
0 개 추천
Huda, when I answered your other question, I suggested that you run 'doc linkage' and gave you a link to the web doc for that function. At the bottom of that page, you can see examples of two different plots. Are you asking for a plot that is not on that page?
Image Analyst
2012년 8월 13일
0 개 추천
Why not just use the scatter() function? If that doesn't work, then explain why not, and use more words to do it.
댓글 수: 31
huda nawaf
2012년 8월 13일
Image Analyst
2012년 8월 13일
You can try this:
data=[1 1;2 2 ; 3 3; 4 4; 5 5; 6 6]
xData = data(:, 1);
yData = data(:, 2);
scatter(xData, yData);
but with the data example you gave, you don't have any clusters at all.
huda nawaf
2012년 8월 13일
huda nawaf
2012년 8월 13일
편집: Walter Roberson
2012년 8월 13일
huda nawaf
2012년 8월 13일
Image Analyst
2012년 8월 13일
If you know what rows are what clusters, then you can pass in different colors for each cluster into scatter(). So cluster 1, 2, and 3 would each have a different color so you can visualize them.
huda nawaf
2012년 8월 13일
Image Analyst
2012년 8월 13일
Come on, you didn't even read the help for scatter() did you? It's right in there. You just pass the colors in as an argument.
huda nawaf
2012년 8월 13일
Walter Roberson
2012년 8월 13일
편집: Walter Roberson
2012년 8월 13일
The number of rows for the first argument to "plotclusters" would be the number of observations. The columns correspond to the dimension. "plotclusters" only works with observations that are 2 or 3 dimensions. Each row of the input matrix would be one observation.
For example if the first observation were at (17.2,8.1,-33) then the first row of the input matrix would be [17.2, 8.1, -33]
huda nawaf
2012년 8월 13일
편집: Walter Roberson
2012년 8월 13일
Walter Roberson
2012년 8월 13일
scatter(x, zeros(size(x)), 5, y)
The zeros() is there to compensate for the fact that you only have a single coordinate for your data, but you need 2 coordinates in order to draw on a graph.
Image Analyst
2012년 8월 13일
huda, yes you can find such a function. Like I said, the scatter() function can draw different clusters with different colors. You just need to make up the color map to reflect that. Here's a demo I wrote just for you:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
numberOfPointsPerCluster = 20
% Make up 3 separated clusters.
cluster1x = 9+rand(numberOfPointsPerCluster,1);
cluster1y = 9+rand(numberOfPointsPerCluster,1);
cluster2x = 9+rand(numberOfPointsPerCluster,1);
cluster2y = 1+rand(numberOfPointsPerCluster,1);
cluster3x = 1+rand(numberOfPointsPerCluster,1);
cluster3y = 1+rand(numberOfPointsPerCluster,1);
allClustersX = [cluster1x; cluster2x; cluster3x];
allClustersY = [cluster1y; cluster2y; cluster3y];
% Make the firstr cluster red, the second green, and the third one blue.
colorMap = zeros(numberOfPointsPerCluster*3, 3);
colorMap(1:numberOfPointsPerCluster,1) = 1;
colorMap(numberOfPointsPerCluster+1:2*numberOfPointsPerCluster, 2) = 1;
colorMap(2*numberOfPointsPerCluster+1:3*numberOfPointsPerCluster, 3) = 1;
% Do the scatterplot with different colors for different clusters.
scatter(allClustersX, allClustersY, 200, colorMap, '+');
% Fancy up the chart.
xlim([0 12]);
ylim([0 12]);
grid on;
xlabel('X', 'fontSize', fontSize);
ylabel('Y', 'fontSize', fontSize);
title('3 clusters with different colors', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
% Give a name to the title bar.
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
huda nawaf
2012년 8월 14일
Image Analyst
2012년 8월 14일
There are a variety of methods such as load(), dlmread(), csvread(), xlsread(), fopen(), textscan(), ActiveX, using the data or image acquisition toolboxes, etc. How did you get data into your other MATLAB programs in the past? Why can't you do it the same way?
huda nawaf
2012년 8월 14일
Walter Roberson
2012년 8월 14일
Everything up to and including AllClustersX and AllClustersY are part of "loading" the data for the purpose of Image Analyst's code.
huda nawaf
2012년 8월 14일
Image Analyst
2012년 8월 14일
Sorry - I never heard of that function.
Ilya
2012년 8월 14일
Slightly modifying the example from the doc page I keep referring to:
X = rand(1000,2);
Z = linkage(X,'complete');
c = cluster(Z,'maxclust',4);
gscatter(X(:,1),X(:,2),c);
All you need to do is replace X = rand(1000,2) with your data and change 4 to the number of clusters you want.
huda nawaf
2012년 8월 14일
Ilya
2012년 8월 14일
I suspect no one here understands what you want to do. Could you please summarize in a few simple sentences: a) What data you have: how many arrays, what they represent, their size, and type, and b) what kind of plot you want to see.
huda nawaf
2012년 8월 15일
Walter Roberson
2012년 8월 15일
How do you want the circles positioned relative to each other?
huda nawaf
2012년 8월 30일
Walter Roberson
2012년 8월 30일
So it is okay if the circles are on top of each other?
Oleg Komarov
2012년 8월 30일
With just the similarity matrix you cannot represent a scatter, but a dendogram.
huda nawaf
2012년 8월 30일
Image Analyst
2012년 8월 31일
Once you know the centers and radius, you can use rectangle() or check the FAQ to draw the colored circles. Try it.
Ilya
2012년 8월 31일
load fisheriris
d = pdist(meas);
Z = linkage(d);
c = cluster(Z,'maxclust',4);
Y = cmdscale(d);
gscatter(Y(:,1),Y(:,2),c)
avadh kushwaha
2021년 5월 6일
how i can draw same image in matlab plsease tell
카테고리
도움말 센터 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!