how show the clusters graphically?
Show older comments
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
Answers (3)
per isakson
on 13 Aug 2012
0 votes
... and the statistical toolbox
3 Comments
huda nawaf
on 13 Aug 2012
Walter Roberson
on 13 Aug 2012
Look at the Description at that link. It describes exactly what each of the parameters means.
Image Analyst
on 13 Aug 2012
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
on 13 Aug 2012
0 votes
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
on 13 Aug 2012
0 votes
Why not just use the scatter() function? If that doesn't work, then explain why not, and use more words to do it.
31 Comments
huda nawaf
on 13 Aug 2012
Image Analyst
on 13 Aug 2012
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
on 13 Aug 2012
huda nawaf
on 13 Aug 2012
Edited: Walter Roberson
on 13 Aug 2012
huda nawaf
on 13 Aug 2012
Image Analyst
on 13 Aug 2012
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
on 13 Aug 2012
Image Analyst
on 13 Aug 2012
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
on 13 Aug 2012
Walter Roberson
on 13 Aug 2012
Edited: Walter Roberson
on 13 Aug 2012
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
on 13 Aug 2012
Edited: Walter Roberson
on 13 Aug 2012
Walter Roberson
on 13 Aug 2012
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
on 13 Aug 2012
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
on 14 Aug 2012
Image Analyst
on 14 Aug 2012
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
on 14 Aug 2012
Walter Roberson
on 14 Aug 2012
Everything up to and including AllClustersX and AllClustersY are part of "loading" the data for the purpose of Image Analyst's code.
huda nawaf
on 14 Aug 2012
Image Analyst
on 14 Aug 2012
Sorry - I never heard of that function.
Ilya
on 14 Aug 2012
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
on 14 Aug 2012
Ilya
on 14 Aug 2012
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
on 15 Aug 2012
Walter Roberson
on 15 Aug 2012
How do you want the circles positioned relative to each other?
huda nawaf
on 30 Aug 2012
Walter Roberson
on 30 Aug 2012
So it is okay if the circles are on top of each other?
Oleg Komarov
on 30 Aug 2012
With just the similarity matrix you cannot represent a scatter, but a dendogram.
huda nawaf
on 30 Aug 2012
Image Analyst
on 31 Aug 2012
Once you know the centers and radius, you can use rectangle() or check the FAQ to draw the colored circles. Try it.
Ilya
on 31 Aug 2012
load fisheriris
d = pdist(meas);
Z = linkage(d);
c = cluster(Z,'maxclust',4);
Y = cmdscale(d);
gscatter(Y(:,1),Y(:,2),c)
avadh kushwaha
on 6 May 2021
how i can draw same image in matlab plsease tell
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!