lundi 23 mars 2020

How to run a loop for variables satifying a specific condition and multiply them with different values?

i need to create a NEW vector in which, starting from the value SP > 0, i can calculate new data starting from h+ 1. In detail I have to multiply SP by 0.1 for its position at h+1, then 0.4 for h+2, then 0.5 for h+3 , summing the corresponding delta. You can see an example in the figure attached. I suppose i have to do it in a cycle but i don’t know how to do it. Anyone can help me? I attached also a picture showing what I need to do:

enter image description here

I tried this way but there is something wrong:

m =[0.1; 0.4; 0.5];
for h = 1:numel(SP)
    if SP(h) > 0
        for ii = 1:length(m)
            new_vector(h+ii,:) = SP(h+ii,:)*m(ii) + delta(h+ii,:)
        end
    else
        new_vector(h,:)= SP(h,:);
    end
end

Thank you in advance!!

Aucun commentaire:

Enregistrer un commentaire