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

3 ビュー (過去 30 日間)
Alfonso Rodriguez
Alfonso Rodriguez 2016 年 5 月 10 日
コメント済み: Alfonso Rodriguez 2016 年 5 月 10 日
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.
  1 件のコメント
Alfonso Rodriguez
Alfonso Rodriguez 2016 年 5 月 10 日
Thanks Again! This knowledge of using a slider is totally new for me. I`m glad you understood my problem.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by