Counting proportion of all rows taken by each unique row
1 回表示 (過去 30 日間)
古いコメントを表示
Hi Everyone,
Suppose I have a matrix A, and I wish to determine the number of unique rows this matrix has. Then I could form B using:
B = unique(A,'rows')
So far, so good. This yields, say, 5 unique rows out of 100.
My problem is the following. Suppose, having found B, I wish to count for each of the 5 unique rows, how many rows are identical ... and then divided by the total number of rows in A, and sort. This will in this case give a 5 x 1 matrix summing to 100%.
How might this be done?
Regards,
Ulrik.
0 件のコメント
採用された回答
Jan
2011 年 7 月 20 日
X = ceil(rand(10, 10) * 5); % Test data
[B, I, J] = unique(X, 'rows');
n = size(X, 1);
H = histc(J, 1:n) / n
4 件のコメント
Andrei Bobrov
2011 年 7 月 21 日
Hi Sean! I think so
X = ceil (rand (10, 10) * 5);% Test date
[B, I, J] = unique (X, 'rows');
H = histc (J, 1: length (I)) / size (X, 1)
その他の回答 (1 件)
Andrei Bobrov
2011 年 7 月 20 日
more variant
[B, I, J] = unique(X, 'rows');
out = diff(find([1; diff(sort(J)); 1]))/length(J)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!