how to normalize a uniformly distributed random values such that every row sum of X(:,:,i) should be 1 except for ith row?

조회 수: 1 (최근 30일)
X = rand([6,3,6]);
how to normalize a uniformly distributed random values such that every row sum of X(:,:,i) should be 1 except for ith row?

채택된 답변

Walter Roberson
Walter Roberson 2021년 8월 16일
X = rand([6,3,6]);
Xn = X ./ sum(X,2);
for i = 1 : min(size(X,1),size(X,3))
Xn(i,:,i) = X(i,:,i);
end
Could it be done without a loop? Probably. Is it worth doing without a loop? That is not clear.
  댓글 수: 6
chan
chan 2021년 9월 29일
Sir could you please help me in this code in modifying...i need every row sum of X(:,:,i) should be 1 except for ith row. This ith row should come from user's choice. if i=3 then all rows should be one except the row 3 in all the matrices...
Walter Roberson
Walter Roberson 2021년 9월 29일
i need every row sum of X(:,:,i) should be 1 except for ith row.
The code already does that. sum(Xn(:,:,1),2) is all 1 except for row 1, sum(Xn(:,:,2),2) is all 1 except for row 2.
This ith row should come from user's choice.
What does the user's choice have to do with it?
Your requirements are that all rows should sum to 1 except X(1,:,1), X(2,:,2), X(3,:,3), X(4,:,4)
if i=3 then all rows should be one except the row 3 in all the matrices...
No, that contradicts your earlier requirements that every row sum of X(:,:,i) should be 1 except for ith row. In the case of i = 3, your requirement is that every row sum of X(:,:,3) should be 1 except for row 3, X(3,:,3) not that the sum should be 1 except for row 3 in all of the matrices, such as X(3,:,2) .
If you had asked for every row sum of X(:,:,:) to be 1 except for row i, i chosen by the user, then that would be a different matter.

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by