필터 지우기
필터 지우기

Counting proportion of all rows taken by each unique row

조회 수: 1 (최근 30일)
Ulrik Nash
Ulrik Nash 2011년 7월 20일
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.

채택된 답변

Jan
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
Sean de Wolski
Sean de Wolski 2011년 7월 20일
Andrei, why the double computation 'n'?
Andrei Bobrov
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
Andrei Bobrov 2011년 7월 20일
more variant
[B, I, J] = unique(X, 'rows');
out = diff(find([1; diff(sort(J)); 1]))/length(J)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by