フィルターのクリア

The code is working very slowly, is there any way to faster?

1 回表示 (過去 30 日間)
net
net 2013 年 11 月 27 日
コメント済み: net 2013 年 11 月 27 日
Hi, I wrote a simple code. I used nested for loops, because of this, the code works very slowly and it gets big time. Is there any way to better and faster work. Thanks for your helps.
for i=1:365
for j=1:8760
a=[g(i),g(i+1),g(i+2),g(i+3),g(i+4),g(i+5),g(i+6),g(i+7),g(i+8),g(i+9), j ];
p(j)= xyz (a,b,c,d);
end
[value,Index]=max(p);
t(i)=Index;
end

採用された回答

Walter Roberson
Walter Roberson 2013 年 11 月 27 日
Well just offhand, you could recode slightly as
a = [g(i:i+9), j];
We cannot do much more without knowing whether xyz is a function or an array. If it is an array, then you are attempting to use 10 indices in the first dimension, and the result is not going to fit into the single location p(j). If it is a function, then all essential speed-up is going to depend upon what the function does and how it can be re-coded to work on vectors.
I get the impression that your xyz is a function that is doing some kind of filtering or convolution ? convolution can be coded more efficiently using conv() or filter()
  1 件のコメント
net
net 2013 年 11 月 27 日
Yes, you are right. xyz is a function that generates a single value. I must focuse to function. Thanks for your help.

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

その他の回答 (0 件)

カテゴリ

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