Replace function

2 次查看(过去 30 天)
nonyt
nonyt 2011-3-31
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 个评论
Andrew Newell
Andrew Newell 2011-3-31
Have you tried "doc unique"?
Matt Fig
Matt Fig 2011-3-31
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Descriptive Statistics 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by