kmeans clustering of matrices/arrays

4 views (last 30 days)
pranesh
pranesh on 5 Jan 2014
Commented: Walter Roberson on 6 Jan 2014
I have a 1X52 cell. Each element of cell is a 33X35 matrix. Need to classify these matrices using kmeans. I tried kmeans(X,k). But it demands X to be a matrix and not a cell.
Is there any other way?
  2 Comments
Wayne King
Wayne King on 5 Jan 2014
Edited: Wayne King on 5 Jan 2014
Are you trying to work with each matrix separately, or are you trying to cluster the large matrix -- (52*33,35)
assuming each row is an observation on 35 variables and the variables are the same for each matrix.
pranesh
pranesh on 5 Jan 2014
yes i want to deal with each matrix separately. The command cell2mat works in the same way as you have mentioned.

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 5 Jan 2014
So make it a 3D array, which I would have done in the first place. Why mess with cells when you don't have to?
Anyway, since you have cells, just extract X from the cell and call kmeans
for c = 1 : length(myCellArray)
X = myCellArray{c}; % Extract double array from cell.
out = kmeans(X,k);
end
  2 Comments
pranesh
pranesh on 6 Jan 2014
thanks. I did that. But still unable to cluster the matrices. I am getting the following message.
??? Error using ==> kmeans>batchUpdate at 435 Empty cluster created at iteration 1.
Error in ==> kmeans at 336 converged = batchUpdate();
Error in ==> name at 51 out = kmeans(X,3);
Walter Roberson
Walter Roberson on 6 Jan 2014
That can happen by chance with random initialization. It can, though, also happen if you have a number of duplicate points.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!