How can I use a slider step to create a graph through a for loop?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Alfonso Rodriguez
am 10 Mai 2016
Kommentiert: Alfonso Rodriguez
am 10 Mai 2016
Hello. I am trying to develop a graph through the use of a slider in a GUI. I can create this graph with a push button. The graph is created through a for loop. This is an educational idea, since I want the users to see the step by step creation of the graph and not just the final graph.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 10 Mai 2016
Yes, you can do that. MATLAB does not distinguish between a uicontrol('style','slider') being stepped (by arrow keys) or directly moved to, in terms of triggering callbacks. So just read out the current Value of the uicontrol, decide how many points of output that implies, take the appropriate subset of the x vector and y vector, update your graph.
If the idea is that each iteration of the loop is to "step" to the next location, then there is no direct way to tell the uicontrol to step. In theory you could use Java Robot to issue the keystrokes, but that is a bit of a waste. get() the current Value, add something to it, set() the Value, call the callback function directly. (When you set() the Value of a uicontrol, that does not trigger a callback, so you need to invoke the callback.)
Better yet, have the callback mostly be getting the current value of the slider and calling an update routine with the current value; then your for loop would just iterate over the values and call the update routine directly, possibly set()'ing the slider Value to imitate the slider being moved along.
Remember to drawnow() after you upgrade graphics in a loop.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!