フィルターのクリア

define new variables based on clustering results

1 回表示 (過去 30 日間)
Hamed Jalali
Hamed Jalali 2020 年 6 月 19 日
コメント済み: Hamed Jalali 2020 年 6 月 27 日
I have some variables, say
X_1, x_2, x_3, x_4, x_5,x_6.
with related matrix of n obeservation X. I have done spectral clustering
idx = spectralcluster(X,k)
to find the clusters of variables. Assume for k=3, the index set is = 2,1,1,3,2,3. Now I want to define new variables
y_1, y_2, y_3 , where y_1={x_2,x_3}, y_2={x_1,x_5}, y_3={x_4,x_6}.
for each clusters. Is there any solution without using for loop.

回答 (1 件)

Raunak Gupta
Raunak Gupta 2020 年 6 月 24 日
Hi,
From the example in the question I understand you have matrix with 6 observation, and you are clustering them into 3 groups. The new variables can be assigned by simply indexing matrix X with corresponding value. Below example might help.
% X = [x_1;x_2;x_3;x_4;x_5;x_6];
idx = spectralcluster(X,k);
y_1 = X(idx==1,:);
y_2 = X(idx==2,:);
y_3 = X(idx==3,:);
  1 件のコメント
Hamed Jalali
Hamed Jalali 2020 年 6 月 27 日
Thanks for your answer. I used the below command:
y_i=X(find(idx==i));
where i is the index of the cluster. It similar to your answer.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by