Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
net
net am 27 Nov. 2013
Kommentiert: net am 27 Nov. 2013
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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 27 Nov. 2013
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 Kommentar
net
net am 27 Nov. 2013
Yes, you are right. xyz is a function that generates a single value. I must focuse to function. Thanks for your help.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by