How to sum elements of matrix in certain condition?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jenjen Ahmad Zaeni
le 16 Jan 2022
Commenté : Jenjen Ahmad Zaeni
le 16 Jan 2022
Hello everyone. I'm sorry if i didn't explain it clearly. I have a matrix like
A =
1.0999 -1.0999 -2.0590 0 -1.0999 0 0
0 0 0.1168 -0.1168 0 -1.0999 0
-2.4128 0 0 -5.2622 0 0 2.4128
I want a new matrix with the same size. The element of new matrix is a sum of other elements in the same column. For example, A(1,1) = 1.0999. The new matrix B(1,1) is a sum of 0 and -2.4128, so B(1,1)=-2.4128. Based on that condition, the new desired matrix is
B =
-2.4128 0 0.1168 -5.3790 0 -1.0999 2.4128
-1.3129 -1.0999 -2.0590 -5.2622 -1.0999 0 2.4128
1.0999 -1.0999 -1.9422 -0.1168 -1.0999 -1.0999 0
All answer will be appreciated. Thank you very much.
0 commentaires
Réponse acceptée
Cris LaPierre
le 16 Jan 2022
A = [1.0999 -1.0999 -2.0590 0 -1.0999 0 0;
0 0 0.1168 -0.1168 0 -1.0999 0;
-2.4128 0 0 -5.2622 0 0 2.4128];
B = [sum(A([2 3],:)); sum(A([1 3],:)); sum(A([1 2],:))]
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!