How can I label my clusters (k-means) ?
Show older comments
I work on diffusion MRI data, and I am trying to do a connectivity-based classification based on --omatrix2 using k-means. FSL (i.e. the diffusion MRI software) gives us the following script to run the clustering algorithm in Matlab :
% Load Matrix2
x=load('fdt_matrix2.dot');
M=full(spconvert(x));
% Calculate cross-correlation
CC = 1+corrcoef(M');
% Do kmeans with k clusters
idx = kmeans(CC,k); % k is the number of clusters
% Load coordinate information to save results
addpath([getenv('FSLDIR') '/etc/matlab']);
[mask,~,scales] = read_avw('fdt_paths');
mask = 0*mask;
coord = load('coords_for_fdt_matrix2')+1;
ind = sub2ind(size(mask),coord(:,1),coord(:,2),coord(:,3));
[~,~,j] = unique(idx);
mask(ind) = j;
save_avw(mask,'clusters','i',scales);
!fslcpgeom fdt_paths clusters
I would like to run this clustering algorithm for each subject, and then make an average over all subjects.
In order to do that, I need to label the clusters in a consistent way - for example, having the cluster with the smallest sum of distances to centroid always labeled 1, and the biggest sum of distances to centroid always labelled 2.
I tried the following code :
for idx = kmeans(CC,2,'Display', 'final')
if 'sumd' < 'final'
idx == 1
else
idx == 2
end
end
But of course it doesn't work...
Error using d_matrix2_cluster (line 9)
Error using lt
Matrix dimensions must agree.
When I replace 'final' by the output value in my command window (e.g. 2050), it does. So I thought of using evalc() but I do not seem to be able to make that work either.
I am very new to Matlab, and a bit stuck - I would be vbery grateful to have the community's help on this. Thank you !
Link to the fsl script: https://fsl.fmrib.ox.ac.uk/fsl/fslwiki/FDT/UserGuide
2 Comments
Image Analyst
on 28 Jun 2019
You forgot to attach 'fdt_matrix2.dot'.
Accepted Answer
More Answers (0)
Categories
Find more on Cluster Analysis and Anomaly Detection 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!