how show the clusters graphically?
3 次查看(过去 30 天)
显示 更早的评论
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
... and the statistical toolbox
3 个评论
huda nawaf
2012-8-13
thanks, I visited that link and run plotcluster: http://www.mathworks.se/matlabcentral/fileexchange/31710-plotclusters-m
but I confused with the first input of this function, the author said that the first input must be n*2 or n*3 and do not know exactly what are the elements of n*2 or n*3 if n is the number of observations , is that meaning I have to creat array with size 6*2 , because i have for examplr 6 observations and the matrix be data=[1 1;2 2 ; 3 3; 4 4; 5 5; 6 6]
I'm not sure, if that proper or not.
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
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?
2 个评论
huda nawaf
2012-8-13
i saw , but I think scatter do not work with my case. please see comments below with image analyst
thanks
Image Analyst
2012-8-13
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
I do not know what X and y represent. where i have 6 points which i need to cluster them and have vector with size 6*1 of indices of clusters for each point.
how I use scatter? there is no any indication about x and y the input of scatter function.
thanks
scatter
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
ok , i know what the result. this is why I asked what X and Y
in my case, i have 6 points , I clustered them into 3 clusters
their clusters:[ 1 2 2 3 1 3]; how I can plot then using scatter?
thanks
huda nawaf
2012-8-13
编辑:Walter Roberson
2012-8-13
walter, of course I read it
he said that
%%% data - an m-by-d matrix, where m is the number of data points to cluster and d is the number of dimensions.%%%%
ok the size of data is m*d, m =6 in my case and d=2.
is that meaning that the no. of rows will be 6 and the no. of columns is 2 if so what are the elements of this array?
thanks
huda nawaf
2012-8-13
this is for image analyst,
in my case I have 6 users,each user have 6 scores that show the rate of similarity with the other user.
now what x and y?
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
yes, that I that want I know the no. of cluster for each row. how I show the clusters with different color
what the inputs of scatter? thanks
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
simply, I have vector
x=[1 5 2 3 4 3 5 5] I need function can draw 1 as cluster with spesific color and 2 with another color, and 3,4,5 . for example cluster 5 with red color in which three samples ,and cluster 3 with different color in which two samples.
can find such function? thanks
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
IMAGE ALYST.
x=[1 2 3 4 5 6];%%%data points
y=[2 3 3 4 1 2];%%indices of clusters
I did that
scatter(x,y,5,'r')
wha i got are six circles with same color.
this plot is meaningless.
the data with same cluster is not grouped in addirion to they has not same color.
i.e the data points 2 and 3, how i can know they are in same cluster?
i deal with large size of data, it is important for me to see the structure of network
thanks
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
thanks for your efforts. this good results
But, I need to know how I can input my data for this code to see my results
many thanks
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
I do mean that of course I know how read my data. That always happen because poor in my language.always happen misunderstanding. what I mean which part of your code deal with data matrix or data vector? so I can adapt your code with my data.
thanks
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
I used plotcluster code , I think I got good result.
PlotClusters(Data,IDX)
where , the first input of function data is m*3 that i got it from linkage function ,but input IDX manually with size m*1. I can got IDX from cluster function but these indices of clusers for each observations (m+1 observations).
how I can get IDX for data?
thanks
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
thanks, but my data is square similarity matrix. I can not use just two colomns . the figure is very good but this function work just for two input. I tried it with the output of linkage function, but not get what I need. I think scatter do not work with my data.
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
I have n*n similarity matrix. ex. n=5 x=[0 3 4 7 8; 3 0 5 2 4; 4 5 0 10 3; 7 2 10 2 1; 8 4 3 1 0];
each row in x is represent the rate of similarity of one user with the others.So, the number of users =5 As u see , it is symmetric matrix.I did clustering for users using ward. The above is just example, my data is large dataset.
I got vector show the index of cluster that each user belong to it. for above example , the vector will be c=[2 2 3 1 3]. simply, for example if we represent each user with circle or anything the drawing will be 2 red circles(user1 and 2), two blue circles(user 3 and 5) and one green circle (user 4)
can do that?
Oleg Komarov
2012-8-30
With just the similarity matrix you cannot represent a scatter, but a dendogram.
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)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Distribution Plots 的更多信息
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)