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

1 Ansicht (letzte 30 Tage)
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?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 16 Aug. 2021
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 Kommentare
chan
chan am 29 Sep. 2021
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 am 29 Sep. 2021
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by