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