Sum of rows in a defined rhythm

1 回表示 (過去 30 日間)
Max Bornemann
Max Bornemann 2019 年 5 月 27 日
コメント済み: Max Bornemann 2019 年 5 月 27 日
Hello everyone,
i have the following array:
A(1:5*270,1)=1;
Now i would like to calculate the sum of every 270th Element. The new array is B. Every element will have the value 5 (1+1+1+1+1). Can someone tell me how i can do that?
The numbers are examples of course. In the original data there is one column with height of 5*270 and after 270 rows the numbers change.
  6 件のコメント
Max Bornemann
Max Bornemann 2019 年 5 月 27 日
Somehow i cant accept your answer, i think it is just a comment. Maybe you can write it as an answer.
Alex Mcaulley
Alex Mcaulley 2019 年 5 月 27 日
Moved to answers :)

サインインしてコメントする。

採用された回答

Alex Mcaulley
Alex Mcaulley 2019 年 5 月 27 日
A(1:5*270,1)=1;
B(1:270,1) = sum(A(270:270:end,1))
  2 件のコメント
Max Bornemann
Max Bornemann 2019 年 5 月 27 日
I have a further question:
I have the following code:
A(1:5*270,1)=1;
A(2,1)=5; % should result in a different value in row 2 in the calculation
The following calculation has the result i want:
B(1:270) = 1+exp(A(1:270))+exp(A(271:540))+exp(A(541:810))+exp(A(811:1080))+exp(A(811:1080))+exp(A(1081:1350));
I am searching for a way to simplify this calculation with help of a sum. I tried to apply your approach, but somehow it doesn´t work (every row has the same value, instead the second should have a different value like above).
B(1:270) = 1+sum(exp(A(270:270:end)));
Max Bornemann
Max Bornemann 2019 年 5 月 27 日
I found a solution :-)
B=1+sum(exp(reshape(A,270,5)),2);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by