Every time I run the code, value of (k) changes. why?
Mostrar comentarios más antiguos
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 comentarios
Ameer Hamza
el 30 de Abr. de 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
el 30 de Abr. de 2020
Eva-Maria Weiss
el 30 de Abr. de 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
el 30 de Abr. de 2020
Editada: Menna Omar
el 30 de Abr. de 2020
Ameer Hamza
el 30 de Abr. de 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.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Get Started with Statistics and Machine Learning Toolbox en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!