Every time I run the code, value of (k) changes. why?
Afficher commentaires plus anciens
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 commentaires
Ameer Hamza
le 30 Avr 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
le 30 Avr 2020
Eva-Maria Weiss
le 30 Avr 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
le 30 Avr 2020
Modifié(e) : Menna Omar
le 30 Avr 2020
Ameer Hamza
le 30 Avr 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.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Get Started with Statistics and Machine Learning Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!