Plotting Clusters using attributes
2 ビュー (過去 30 日間)
古いコメントを表示
I'm trying to plot a clusters using the code below. The attribs are initially = [1 2 3], however as I attempt to change it to [60 61 62] it says ' Index exceeds the number of array elements'.
I dont understand this because when I run the code with [1 2 3] it outputs a cluster plot with columns 1, 2, 3 from my table/data. And so, because I to create clusters from columns [60 61 62], I dont understand why it would output an exceeeding error.
figure(1)
colstyle = {'cs','rd','b^','go','k+','d',':bs','-mo'}; %define 8 color/style combos for this plot
attribs=[60 61 62]; %categories for x, y, and z axes
for j=1:k
q=find(clust==j); %ID numbers of the items in this cluster
nsample(j)=length(q); %Sample size in the cluster
debt(j)=mean(B_train(q)); %Survival rate within this cluster
plot3(A_train(q,attribs(60)),A_train(q,attribs(61)),A_train(q,attribs(62)),colstyle{j}) % 3-D plot with marker types by cluster
hold on
end
hold off
legend('Cluster 1','Cluster 2','Cluster 3','Cluster 4','Cluster 5','Cluster 6','Cluster 7','Cluster 8');
xlabel(all_factors(attribs(60)));
ylabel(all_factors(attribs(61)));
zlabel(all_factors(attribs(62)));
0 件のコメント
回答 (1 件)
Anay
2025 年 6 月 30 日
編集済み: Anay
2025 年 6 月 30 日
Hi Alayt,
The “attribs” array contains only 3 elements while the code is accessing 60th element. This gives rise to the “Index exceeds the number of array elements” error.
In MATLAB there are many ways to access array elements based on their location. The location of an element in the array is known as “index”. The code given in the question uses “linear indexing” which means accessing array elements using a single index.
You can consider following the below link to learn more about Array Indexing in MATLAB:
“attribs(i)” corresponds to the element at the position “i” in “attribs”. In the code, “attribs(60)” means element at 60th position in the “attribs” array. But attribs has only 3 elements. Thus, the index which you are trying to access is “out of bounds”. So, to create clusters from columns 60, 61 and 62, use “attribs = [61,62,63]” but make the following change in your code
plot3(A_train(q,attribs(1)),A_train(q,attribs(2)),A_train(q,attribs(3)),colstyle{j})
xlabel(all_factors(attribs(1)));
ylabel(all_factors(attribs(2)));
zlabel(all_factors(attribs(3)));
Now, “attribs(1)” would correspond to 60 and so on. This will resolve the “out of index” error and plot the desired output.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Cluster Analysis and Anomaly Detection についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!