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