Need Help with MATLAB Fuzzy Clustering - Trouble Implementing Example
11 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello MATLAB Enthusiasts,
I hope you're all doing well. I've been working on a project where I'm trying to implement a fuzzy clustering algorithm, and I've encountered a roadblock while trying to adapt an example I found on the MATLAB website. Here's the link to the example: [Fuzzy C-Means Clustering Example](https://www.mathworks.com/help/fuzzy/fcm.html)
My Problem:
I'm working with a dataset named "aaaa.dat," which is a 58x3 matrix. My goal is to apply the Fuzzy C-Means (FCM) clustering algorithm to this dataset. However, I've been facing some issues while trying to run the provided example code.
Here's the Code I Tried:
%%
load aaaa.dat
options = fcmOptions(...
NumClusters=[2 3 4],...
Verbose=false);
[centers,U,objFun,info] = fcm(aaaa,options);
Nc = info.OptimalNumClusters;
info.ValidityIndex
maxU = max(U);
index1 = find(U(1,:) == maxU);
index2 = find(U(2,:) == maxU);
index3 = find(U(3,:) == maxU);
figure
hold on
scatter3(aaaa(index1,1),aaaa(index1,2),...
aaaa(index1,3))
scatter3(aaaa(index2,1),aaaa(index2,2),...
aaaa(index2,3))
scatter3(aaaa(index3,1),aaaa(index3,2),...
aaaa(index3,3))
plot3(centers(:,1),centers(:,2),centers(:,3), ...
"xk",MarkerSize=15,LineWidth=3)
xlabel("Feature 1")
ylabel("Feature 2")
zlabel("Feature 3")
view([-11 63])
hold off
The Error I'm Encountering:
After running the code, I'm getting the following output in the command window:
ans =
0.0377 0.5137 0.2409
Index in position 1 exceeds array bounds. Index must not exceed 2.
Error in testCluster (line 28)
index3 = find(U(3,:) == maxU);
I've reviewed my code multiple times, but I'm unable to pinpoint what I might be doing wrong. It's quite frustrating, and I would greatly appreciate any insights, suggestions, or tips you can offer.
If you've worked with Fuzzy C-Means clustering in MATLAB or have any ideas on what might be causing the issue, please share your thoughts. Your assistance would be invaluable to me.
Thank you in advance for your help!
0 comentarios
Respuestas (1)
Sam Chak
el 19 de Sept. de 2023
Hi @Baptiste
Please take a look at this example. The data set is specified as a matrix with 9 rows, each representing a data point. If the FCM algorithm finds 2 cluster centers, as in this data set, then the fuzzy partition matrix U will be returned as a
matrix. Thus, in cases where the third row does not exist, the syntax 'index3 = find(U(3,:) == maxU)' will throw an index error.
aaaa = rand(9, 3)
options = fcmOptions(...
NumClusters = [2 3 4], ...
Verbose = false);
[centers, U, objFun, info] = fcm(aaaa, options)
Nc = info.OptimalNumClusters;
info.ValidityIndex
maxU = max(U);
index1 = find(U(1,:) == maxU)
index2 = find(U(2,:) == maxU)
index3 = find(U(3,:) == maxU)
2 comentarios
Ver también
Categorías
Más información sobre Data Clustering en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
