Unusual slowdown using sum.

Matlab handles sums of arrays pretty well, but seems to have trouble with my application. I do a bit of work with double precision numbers early in the code, then want to take a 1000x1000 array and produce a 1000x1000x1000 with said array. I've done things like this before with larger dimensions and larger numbers of dimensions with output results in milliseconds. The cataclysmic code is here:
for nn = 1:1000
for mm = 1:1000
if (nn < mm)
Temparray = Loss(nn:mm,:);
Grandarray(nn,mm,:)= sum(Temparray,1);
end
end
end
Because of the symmetry of the problem I only have to compute the equivalent of the upper-right corner. Is there something I'm inherently doing wrong, or is the computation simply enormous?

2 件のコメント

Walter Roberson
Walter Roberson 2018 年 10 月 16 日
It looks to me as if you could probably make use of cumsum() for efficiency, unless the difference in round-off would be too much for you.
Matthew Reed
Matthew Reed 2018 年 10 月 17 日
Thank you very much! You've sped this up by an order of magnitude. Thank you for helping an amateur.

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

回答 (1 件)

James Tursa
James Tursa 2018 年 10 月 12 日

0 投票

Are you pre-allocating Grandarray?

カテゴリ

ヘルプ センター および File ExchangeShifting and Sorting Matrices についてさらに検索

質問済み:

2018 年 10 月 12 日

コメント済み:

2018 年 10 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by