Assignment statement very time consuming

5 ビュー (過去 30 日間)
Bryan Ehlers
Bryan Ehlers 2021 年 12 月 14 日
回答済み: Walter Roberson 2021 年 12 月 15 日
I ran the profiler on a time consuming function that I have and found that the most time consuming line of code is:
avgVal(:, :, k) = mean(val);
I preallocate the avgVal and val is an array of numbers. I'm wondering is there something I'm doing that is inefficient? The only reason I could think of is that the first and second dimensions of avgVal are large so this statement is requiring a lot of entries to be filled in.
Is there anything that I may be overlooking?
Edit:
The size of avgVal is 4000-by-100-by-6 and the size of val is 36-by-1.
  2 件のコメント
James Tursa
James Tursa 2021 年 12 月 15 日
We need to see the surrounding code and the actual sizes involved.
Bryan Ehlers
Bryan Ehlers 2021 年 12 月 15 日
I have added the sizes

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

回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 12 月 15 日
Are you sure that you want to set an entire 4000 x 100 slice of avgVal to be the same scalar? With val being 36 by 1, mean() of it would be a scalar.
If you are doing all 6 slices, it would possibly be faster to record the 6 means as a 1 x 1 x 6 vector, and then repmat() it to the 4000 x 100 x 6 size.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by