BTW, this pice runs horribly slow. No reason to use a double-for loop and touching data back and forth
r=1;
for p=1:pas_reseau:p_max-pas_reseau
delta_p(r) = 0;
for k=p:p+pas_reseau
delta_p(r) = delta_p(r) + p_reseaupos(k) - p_souscrite;
end
delta_p(r) = delta_p(r)/ pas_reseau;
r =r+1;
end
You're simply doing (and this can be simplified further with a cumsum, but the gain is not that large)
r=1;
for p=1:pas_reseau:p_max-pas_reseau
delta_p(r) = (sum(p_reseaupos(p:p+pas_reseau
))-(pas_reseau+1)*
p_souscrite)/pas_reseau
;
r =r+1;
end
However,
I don't see why you define delta_p first, and then kill the elements
with new stuff. The best approach (if not vectorizing with cumsum etc)
would be
delta_p = [];
for p=1:pas_reseau:p_max-pas_reseau
delta_p = [delta_p;(sum(p_reseaupos(p:p+pas_reseau))-(pas_reseau+1)*p_souscrite)/pas_reseau];
end
(and then add some trailing crap, since you expect this vector to have a certain length, although you only set some part of it)