save n-Numbers of last interation from a loop
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
hello
i want to save always the last n (n between 1 and 6) interation of a loop.
i have a regulator which is read out in a loop. now i need always the last n inerations of the loop to calculate the desirerd condition.
function ReglerButtonPushed(app, event)
k= app.KWertSlider.Value;
bereich= app.BereichSlider.Value;
speed= app.SpeedSlider.Value;
fehlervek= zeros(6,1);
l
app.stopRegler = false;
while app.stopRegler == false
b = getBrightness(app,app.sensorPos(1),app.sensorPos(2));
app.HelligkeitEditField.Value=b;
fehler = b - 0.5; %actual mistake
i know how to save all mistakes - i just need the actually last n interations.
0 commentaires
Réponse acceptée
Jan
le 28 Nov 2018
n = 6;
fehlerVec = nan(1, n);
while app.stopRegler == false
b = getBrightness(app,app.sensorPos(1),app.sensorPos(2));
app.HelligkeitEditField.Value=b;
fehler = b - 0.5; %actual mistake
fehlerVec = [fehler(2:n), fehler];
end
Now fehlerVec contains the last n elements. There are more efficient solutions, but collecting these n values is most likely not the time-crticial part.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!