필터 지우기
필터 지우기

Calculating the marginal distribution from the joint distribution table

조회 수: 6 (최근 30일)
skyline
skyline 2017년 6월 5일
댓글: Jan 2017년 7월 5일
I would like to write down a function that generates the marginal distribution table from the joint distribution table.
Specifically, suppose I have a table
A =
[0.1 0 0.1; 0.1 0.1 0.1; 0.2 0 0.2; 0.2 0.1 0.2; 0.2 0.2 0.2]
where the first column is denoted x and the second column is denoted y
Then I would like to create a marginal distribution table where
- the first column is the distinct values of the first column of A (that is, the distinct values of x)
- the second column is the marginal distribution of x.
For example, the first (1,2)th element is the average of the entry of the third column of A where the first column is 0.1 (i,e. the marginal distribution for 0.1)
Please advise.
  댓글 수: 1
Jan
Jan 2017년 7월 5일
"Please advice" : The most important advice is that you should stop to remove the text of your questions, after they have been answered. This is disliked here and counterproductive. The answers are posted to let the community profit from the solution. Editing the question away converts the thread to confusing junk.
Please, skyline, stop this deleting.

댓글을 달려면 로그인하십시오.

답변 (1개)

Star Strider
Star Strider 2017년 6월 5일
I’m not quite certain what you want.
See if this works:
A = [0.1 0 0.1; 0.1 0.1 0.1; 0.2 0 0.2; 0.2 0.1 0.2; 0.2 0.2 0.2];
[Au,~,ic] = unique(A(:,1));
Result = accumarray(ic, A(:,3), [], @mean);
Output = [Au, Result]
Output =
0.1 0.1
0.2 0.2

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by