how to sum all row values in a matrix except the ith row?
8 views (last 30 days)
i have a matrix X=rand([6,3,6]);
I want all the row value sum=1 except the ith row? this ith can be 4/5 according to user's choice? all the matrices row sum will be 1 except the ith row in every matrices? Here i dnt want to exclude the ith row. the elements of the ith row will be there as it is. could someone help me in solving this problem
DGM on 29 Sep 2021
Edited: DGM on 29 Sep 2021
There are probably other ways, but here's a way (if I understand the question correctly).
A = rand(6,3,6);
dnn = 5; % do not normalize this row
Adn = A(dnn,:,:); % save this row
A = A./sum(A,2); % normalize
A(dnn,:,:) = Adn; % replace the row
sum(A,2) % show that the row sums are 1 except where specified
That will normalize all rows except the specified row. I should point out that while this method discards the normalized results for one row, it's faster than indexing