Assigning class +1/-1 to a 100x2 matrix

1 回表示 (過去 30 日間)
Deepayan Bhadra
Deepayan Bhadra 2018 年 2 月 20 日
コメント済み: Deepayan Bhadra 2018 年 2 月 20 日
I have a 100x2 matrix D. A scatter plot is attached. I have a 100x1 vector 'c'. If a point in D is to the left, I want to assign it as +1 and -1 otherwise. I know it sounds easy and I was trying this snippet:
if D(1:100,1)<mean(D(:,1)) c(:,1) = 1; else c(:,1) = -1; end
but it somehow doesn't do the job. I think we don't even need an if loop. Thanks for your comments.

採用された回答

Cam Salzberger
Cam Salzberger 2018 年 2 月 20 日
Hello Deepayan,
You probably are trying to use logical indexing, so you don't need the conditional.
c = ones(size(D, 1), 1);
c(D(:, 1) > mean(D(:, 1))) = -1;
On the other hand, you've got some very nice clusters here, and this code depends on you having roughly equal number of points in each cluster. Rather than mean, it would probably make sense to use some form of cluster analysis to figure out where the clusters are, and which points belong to which. kmeans is one of the most common methods, and would probably suffice here.
-Cam
  1 件のコメント
Deepayan Bhadra
Deepayan Bhadra 2018 年 2 月 20 日
Thanks, Cam! Pretty much what I needed and I will also check the clustering bit.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by