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

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by