Azzera filtri
Azzera filtri

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

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Walter Roberson
Walter Roberson il 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 Commento
net
net il 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by