Filter löschen
Filter löschen

Sum of columns with certain window

1 Ansicht (letzte 30 Tage)
Miroslav Josic
Miroslav Josic am 30 Jan. 2017
Kommentiert: Miroslav Josic am 30 Jan. 2017
Hi guys
I need your help with summing columns based on certain window as I could not find a solution already discussed. I have a matrix of size 2,159x372 where in every 6 columns I have specific industry data for one country (total of 62 countries). So, I would like to sum columns 1-6, 7-12, 13-19 etc in order to get only country data in columns. It means I would have in the end a matrix of size 2,159x62.
I guess I have to use for loop but I am just not clear how to set the window.
Miroslav

Akzeptierte Antwort

Jan
Jan am 30 Jan. 2017
Bearbeitet: Jan am 30 Jan. 2017
Data = rand(2159, 372);
Data = reshape(Data, 2159, 6, 62);
Result = reshape(sum(Data, 2), 2159, 62);
This splits the 2nd dimension after all 6 elements shifting the rest to the 3rd dimension. After calculating the sum, the inserted dimension is removed again. squeeze(sum(Data, 2)) would be an option also.
  1 Kommentar
Miroslav Josic
Miroslav Josic am 30 Jan. 2017
Hi Jan,
Thank you very much! It works perfectly.
I thought a loop should be used, but was wrong.
Appreciate your help a lot!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements 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!

Translated by