How to normalize a matrix in such a wat that every row sum of X(:,:,i) should be 1 except for ith row

1 次查看(过去 30 天)
I have created a matrix X = rand([6,3,6]); i want to normalize this matrix in such a way that every row sum of X(:,:,i) should be 1 except for ith row.
Inside an while(1) loop ,i have
i=randi(n);
Say for example when i=2 that particular row sum should not be equal to one. same goes for other node.How it can be done?
  3 个评论
chan
chan 2021-10-24
in an infinite loop this i (node) value will keep on changing. based on that value of i , the matrix will be normalize except this particular i (node).
if i=2 only that particular row will not be normalize while others row wiil be equal to 1. it will be same for other i's based on the random value generated.
Jan
Jan 2021-10-24
@IRANI ACHARJAMAYUM: What yre your inputs? How does X = rand([6,3,6]) and an infinite loop with i=randi(n) match? What is the wanted output?
It is still not clear, what you want to achieve. I've posted some code for normalizing the rows of a 3D array except for certain indices. Does it work? If not, what have to be changed?

请先登录,再进行评论。

回答(2 个)

Cris LaPierre
Cris LaPierre 2021-10-23
Why not just create a row vector of random numbers, and insert it into a matrix of ones?

Jan
Jan 2021-10-23
编辑:Jan 2021-10-23
X = rand(6, 3, 6);
N = sum(X, 2);
N(sub2ind(size(N), 1:6, ones(1,6), 1:6)) = 1;
Y = X ./ N;
Now sum(Y(i, :, j)) is 1 is i~=j.
sum(Y(1, :, 2))
ans = 1
sum(Y(3, :, 3))
ans = 1.5543

类别

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