Sum specific dimension in matrix
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I attached a matrix that consist of 7X9X240.
The 3rd dimension is time(20years X 12Month=240).
So I want to pick January ~March in every year and Sum all of them.
-> Matrix(:,:,1),(:,:,2),(:,:,3),(:,:,13),(:,:,14),(:,:,15)~
I mean, Sum each rows and colums.
So I hope 7X9 matrix ultimately.
How can I get the result?
In advence, thank you.
0 Kommentare
Akzeptierte Antwort
Karim
am 22 Dez. 2022
Hello, in the demo code below you can find some comments and a procedure on how to get the indexes, extract the data and sum over the third dimension.
load("Matrix.mat")
% create the indexes
Jan_Idx = 1 : 12 : 20*12; % january
Mar_Idx = 3 : 12 : 20*12; % march
% create the indexes for january and march
Idx = sort( [Jan_Idx Mar_Idx] )
% extract these monts from the data
MyData = TDDb( :,:,Idx );
% now sum over the third dimension
MyData = sum( MyData, 3)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical 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!