Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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?

Respuesta aceptada

Walter Roberson
Walter Roberson el 16 de Ag. de 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 comentarios
chan
chan el 29 de Sept. de 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 el 29 de Sept. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by