How can I use a slider step to create a graph through a for loop?

1 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2016-5-10
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by