Hi
I have attached my scatter poit figure and I want to make a 2 or 3 clusters from them.
This is my code;
for i = 1:size(MeanEchos,1);
for j = 1:size(MeanEchos,2);
scatter(blob_area{2,j},MeanEchos{2,j},'x');
set(gca,'xscale','log');
grid on;
xlabel('Blob Area');
ylabel('Mean Echo Intensity');
xlim([0 10^5]);
ylim([0 5])
end
end
I would be greateful if anyone would be able to help me.
Thanks in advance

 Réponse acceptée

Ameer Hamza
Ameer Hamza le 17 Oct 2020

0 votes

If you have statistical and machine learning toolbox, then try kmeans(): https://www.mathworks.com/help/releases/R2020b/stats/kmeans.html

7 commentaires

Fatemeh Shomal Zadeh
Fatemeh Shomal Zadeh le 17 Oct 2020
Thanks! how I can make 1 array from these two double cell array blob_area{2,j} and MeanEchos{2,j}?
because when I want to use kmeans, it needs to be one array.
blob area here is x of my figure and means echos is y.
I think following should work
x1 = [blob_area{2,:}].';
x2 = [MeanEchos{2,:}].';
X = [x1 x2];
Input X to kmeans(). If there is an error, can you attach the variables blob_area and MeanEchos in a .mat file.
Fatemeh Shomal Zadeh
Fatemeh Shomal Zadeh le 18 Oct 2020
Thanks so much for your respond. I do really appreciate it.
With the new code that you ahve sent, I am receiving an error of 'Vectors must be the same length.'
I have attached my data here. Baically as you can see in the screen shot od scatter point, the first distribution needs to be cluster #1 and second distribution needs to be cluster #2.
Ameer Hamza
Ameer Hamza le 18 Oct 2020
These lines wok without error on my machine. How are you typing these lines?
Fatemeh Shomal Zadeh
Fatemeh Shomal Zadeh le 18 Oct 2020
Yes you are right. I used your code and thanks so much for that.
However, I want to make sure that I am receieving the right resualt.
My all lines are stated as bellow;
x1 = [blob_area{3,:}].';
x2 = [MeanEchos{3,:}].';
X = [x1 x2];
opts = statset('Display','final');
[idx,C] = kmeans(X,2,'Distance','cityblock',...
'Replicates',255,'MaxIter',1000,'Options',opts);
figure;
plot(X(idx==1,1),X(idx==1,2),'r.','MarkerSize',12)
hold on
plot(X(idx==2,1),X(idx==2,2),'b.','MarkerSize',12)
plot(C(:,1),C(:,2),'kx','MarkerSize',15,'LineWidth',3)
legend('Cluster 1','Cluster 2','Centroids',...
'Location','NW')
title 'Cluster Assignments and Centroids'
hold off
I attached the figure as well. based on the initial figure, is my result right?
Also, thanks so much for all your help, with that 2 lines I got my answer after 2 days working.
Ameer Hamza
Ameer Hamza le 18 Oct 2020
From the images, it seems that the results are correct. It clearly shows two clusters. I am glad to be of help!
Fatemeh Shomal Zadeh
Fatemeh Shomal Zadeh le 18 Oct 2020
Great. Thanks a lot!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by