Effacer les filtres
Effacer les filtres

Replace function

2 vues (au cours des 30 derniers jours)
nonyt
nonyt le 31 Mar 2011
Hello, I have the following function,
function label = litekmeans(X, k) n = size(X,2); last = 0; label = ceil(k*rand(1,n)); % random initialization while any(label ~= last) [~,~,label] = unique(label); % remove empty clusters E = sparse(1:n,label,1,n,k,n); % transform label into indicator matrix center = X*(E*spdiags(1./sum(E,1)',0,k,k)); % compute center of each cluster last = label; [~,label] = max(bsxfun(@minus,center'*X,0.5*sum(center.^2,1)')); % assign samples to the nearest centers end
I have to replace the 'unique' and the 'spdiags' function. I am allowed to use only built in functions.
I am quite new in matlab and i can't understand how those 2 functions work here.
Can anyone explain me what are they actually doing or how they work.
I will need to understand how they work so be able to replace them.
Can anyone help me? Thanks nonyt!
  3 commentaires
Andrew Newell
Andrew Newell le 31 Mar 2011
Have you tried "doc unique"?
Matt Fig
Matt Fig le 31 Mar 2011
First off, please go back and use the {} Code button after highlighting the code you pasted into the window, then delete your comment where you pasted it again.
Second, you can learn exactly what goes on with the UNIQUE function by typing:
edit unique
the reading the function.

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Sparse Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by