using cumsum for a vector

6 ビュー (過去 30 日間)
C.G.
C.G. 2021 年 8 月 18 日
回答済み: Cris LaPierre 2021 年 8 月 18 日
I have a variable GT2, which is a 1x900 double.
I am trying to do a cumulative sum, where for each cell it does a cumulative sum up to that point, dives this by how many numbers has been summed, and then take the square root.
The current code I have for this is below. When I run this code, it creates a 900x900 double. All I want it to do is do that calculation for each cell so I end up with the same number of values (900) as in GT2. Can anybody help?
flucc = sqrt(cumsum(GT2)./time);

回答 (1 件)

Cris LaPierre
Cris LaPierre 2021 年 8 月 18 日
Check your dimensaion. Your cumsum will be a 1xn vector. I suspect time must be an nx1. When you perform the division, implicit expansion will turn this into an nxn. The fix would be to transpose time.
% (1xn)./(1xn) = (1xn)
a = cumsum(1:4)./ones(1,4)
a = 1×4
1 3 6 10
% (1xn)./(nx1) = (nxn)
b = cumsum(1:4)./ones(4,1)
b = 4×4
1 3 6 10 1 3 6 10 1 3 6 10 1 3 6 10

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by