Every time I run the code, value of (k) changes. why?
Show older comments
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 Comments
Ameer Hamza
on 30 Apr 2020
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
on 30 Apr 2020
Eva-Maria Weiss
on 30 Apr 2020
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
on 30 Apr 2020
Edited: Menna Omar
on 30 Apr 2020
Ameer Hamza
on 30 Apr 2020
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.
Accepted Answer
More Answers (0)
Categories
Find more on Get Started with Statistics and Machine Learning Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!