Hi there, I am trying to implemement my own K means function without using the unbuilt function 'kmeans'.
I started with some complex waveform data and reduced the dimensionality to 2 PC and plotted on a scatter, 3 distinct clusters emerge.
to do k means first i set random centroids within the range of the data - e.g.
centroids = min(wav_pca) + (max(wav_pca)-min(wav_pca)).* rand(k,1)
this gives me starting centroids - howevr i don't this the distribution is as random as i'd like.
then I have to compute the euclidean distance from each point to a centroid and assign it to the one with the shortest distance
distance=sqrt( (centroids(j,1)- wav_pca(i,1))^2 + (centroids(j,2)- wav_pca(i,2)^2) )
for this I tried to use this for loop but it's not creating the matrix of distances that I need.
then each point must be assigned to it's closest centroid, giving it a cluster ID
the cluster centroids need to be recomputed as an average of all the assigned points and the points reassigned, this needs to be iterated though until the assignments change and I am unsure how to do this.
thanks for all that you can help with, if you need any more info let me know, and apologies for being new to matlab.