Every time I run the code, value of (k) changes. why?
이전 댓글 표시
function [label] = clutseringData (Data , C)
dis = zeros(size(Data,1), size(C,1));
label = zeros(size(Data,1), 1);
for i = 1:size(Data,1)
for j = 1:size(C,1)
dis(i, j) = norm(Data(i,:) - C(j, :));
end
end
for k = 1:size(Data,1)
label(k) = find( dis(k,:) == min(dis(k,:)) );
end
end
댓글 수: 5
Ameer Hamza
2020년 4월 30일
What are the values of input argument Data and C? What do you mean that value of k changes? It is a counter variable for a for-loop, therefore it will change from 1 to size(Data,1).
Menna Omar
2020년 4월 30일
Eva-Maria Weiss
2020년 4월 30일
I'm not so sure about that, but for my understanding, for the case your program runs without error, k shouldn't be in the workspace at all, since it's not an output variable. So I would suspect, that the k that you see in you workspace could be from former tests, where you ight have set some breakpoint or something like that. I don't now---the length of label is correct?
Menna Omar
2020년 4월 30일
편집: Menna Omar
2020년 4월 30일
Ameer Hamza
2020년 4월 30일
Menna, I guess that you are trying to find the index of the minimum value in the dis. Right? What if there are two equal minimum values.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Get Started with Statistics and Machine Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!