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 天)
how to normalize a uniformly distributed random values such that every row sum of X(:,:,i) should be 1 except for ith row? 'i' value can be anything according to user's choice.
X = rand([n,key_size,6]); where n=6,key_size=3
Here 6 matrices created. Here i want row 5 not to be normalized in all the 6 matrices and keep the original value and all the other row sum of this 6 matrices be normalized? could somone help me in solving this problem. I would be very grateful. thank you

回答(1 个)

Chunru
Chunru 2021-9-29
编辑:Chunru 2021-9-29
n=6; key_size=3; i=5;
X = rand([n,key_size,6]);
idx = [1:i-1 i+1:n];
X (idx, :, :) = X (idx, :, :)./sum(X (idx, :, :), 2);
X
X =
X(:,:,1) = 0.1963 0.2355 0.5682 0.4084 0.3829 0.2087 0.4225 0.2156 0.3619 0.6109 0.1880 0.2010 0.3553 0.0219 0.1098 0.0393 0.7273 0.2334 X(:,:,2) = 0.4083 0.3940 0.1977 0.3497 0.2938 0.3565 0.4196 0.5791 0.0013 0.6651 0.1788 0.1561 0.7057 0.9660 0.4752 0.3116 0.1548 0.5336 X(:,:,3) = 0.1459 0.7574 0.0967 0.3566 0.5568 0.0866 0.3424 0.3153 0.3423 0.0998 0.5528 0.3474 0.4512 0.6269 0.0229 0.1695 0.4982 0.3323 X(:,:,4) = 0.1744 0.2141 0.6114 0.4465 0.4234 0.1301 0.1581 0.2629 0.5790 0.4688 0.5284 0.0028 0.7126 0.7236 0.9397 0.2849 0.2578 0.4573 X(:,:,5) = 0.0353 0.2395 0.7252 0.3029 0.3668 0.3302 0.6438 0.2772 0.0790 0.5217 0.3985 0.0798 0.6972 0.2128 0.6599 0.2101 0.2926 0.4973 X(:,:,6) = 0.3236 0.3221 0.3543 0.5614 0.0772 0.3614 0.4919 0.5050 0.0031 0.1608 0.3910 0.4482 0.3994 0.9686 0.3631 0.3526 0.1925 0.4549
sum(X, 2)
ans =
ans(:,:,1) = 1.0000 1.0000 1.0000 1.0000 0.4870 1.0000 ans(:,:,2) = 1.0000 1.0000 1.0000 1.0000 2.1470 1.0000 ans(:,:,3) = 1.0000 1.0000 1.0000 1.0000 1.1010 1.0000 ans(:,:,4) = 1.0000 1.0000 1.0000 1.0000 2.3759 1.0000 ans(:,:,5) = 1.0000 1.0000 1.0000 1.0000 1.5698 1.0000 ans(:,:,6) = 1.0000 1.0000 1.0000 1.0000 1.7310 1.0000

标签

Community Treasure Hunt

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

Start Hunting!

Translated by