How to sum elements of matrix in certain condition?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jenjen Ahmad Zaeni
am 16 Jan. 2022
Kommentiert: Jenjen Ahmad Zaeni
am 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 Kommentare
Akzeptierte Antwort
Cris LaPierre
am 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],:))]
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!