save n-Numbers of last interation from a loop
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Jan
il 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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!