Need Matrix operation HELP
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mahmoud Ahmed
am 16 Mai 2017
Kommentiert: James Tursa
am 16 Mai 2017
If I have:
T(:,:,1) =
1 2 3
4 5 6
7 8 9
T(:,:,2) =
1 4 7
2 5 8
3 6 9
I want to convert each matrix to be vector contains [(the sum of 1st row) (the sum of 2nd row) (the sum of 3rd row)] for example: Convert T(;,:,1) to be [6 15 24] where: 6 = 1+2+3 , 15 = 4+5+6 , 24 = 7+8+9 The same, Convert T(:,:,2) to be [12 15 18] where: 12 = 1+4+7 , 15 = 2+5+8 , 18 = 3+6+9 .. What's the function that can do it?
0 Kommentare
Akzeptierte Antwort
Star Strider
am 16 Mai 2017
Use the sum function, specifying to sum acroww rows (dimension 2).
Example —
T1 = [1 2 3
4 5 6
7 8 9];
T2 = [1 4 7
2 5 8
3 6 9];
T = cat(3,T1,T2);
T_row_sum = sum(T,2)
T_row_sum(:,:,1) =
6
15
24
T_row_sum(:,:,2) =
12
15
18
1 Kommentar
James Tursa
am 16 Mai 2017
Did you try the code when you have a T(:,:,3) and T(:,:,4) to see what it does?
Weitere Antworten (1)
Siehe auch
Kategorien
Mehr zu Data Types 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!