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?
0 件のコメント
採用された回答
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 件のコメント
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 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!