Replace function

2 Ansichten (letzte 30 Tage)
nonyt
nonyt am 31 Mär. 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 Kommentare
Andrew Newell
Andrew Newell am 31 Mär. 2011
Have you tried "doc unique"?
Matt Fig
Matt Fig am 31 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Descriptive Statistics finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by