control for-loop index using a gui slider

1 Ansicht (letzte 30 Tage)
Oscar
Oscar am 14 Feb. 2018
Beantwortet: Jos (10584) am 14 Feb. 2018
I'm on an older version of Matlab (2011a) and am trying to set up an interactive loop. I am for-looping through a time vector, and would like to control the index via a gui slider. How would you go about solving that? A play/stop function that works together with a plotting function. Most other questions on the topic relate to stopping loops using gui functions which isn't quite the idea here.

Akzeptierte Antwort

Jos (10584)
Jos (10584) am 14 Feb. 2018
My first recommendation would be to use an infinite while loop. Fo starters, in pseudocode:
function StartButtonPressed
% this function executes when you hit the start button
% initialise things here
while true
k = GetValueFromSlider ; % k = current time
if k < MaxValue
k = k + 1 ; % increment time
% code to update plot here
% code to set slider value to k
end
if StopButtonPressed
break
end
end
% code to clean up things go here

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 14 Feb. 2018
You might want to adapt video_fig from the File Exchange.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by