フィルターのクリア

Using clusterdata and extracting data from it's indexes.

2 ビュー (過去 30 日間)
Izuru
Izuru 2015 年 4 月 15 日
コメント済み: Izuru 2015 年 4 月 15 日
Hello,
I have an array of points say A = [1,13,14,2,15,16,3,17];
I use clusterdata (with criterion as distance) which returns me the cluster number each data point in A belongs to:
T = [1,2,2,1,2,2,1,2];
I want to have a new array which separates these data points into:
B = [1,2,3] C = [13,14,15,16,17]
How do I achieve this?

採用された回答

Guillaume
Guillaume 2015 年 4 月 15 日
編集済み: Guillaume 2015 年 4 月 15 日
A very simple but possibly obscure way is to use accumarray:
Asplit = accumarray(T', A, [], @(v) {v});
Note that the output is a cell array where each cell is a cluster. It's much better to use a cell array than individually named variables.
The above line is equivalent to:
Asplit = cell(max(T), 1);
for cluster = 1:max(T)
Asplit{cluster} = A(T == cluster);
end
  2 件のコメント
Izuru
Izuru 2015 年 4 月 15 日
That worked great thanks. One more simple question, the output I get says:
Asplit = [20x1 single] [16x1 single] etc
How do i display the values of that array? Sorry it's been a while since using matlab...
Izuru
Izuru 2015 年 4 月 15 日
Never mind I found it! Cheers

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by