How can I use a slider step to create a graph through a for loop?
3 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
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 Center および File Exchange で Migrate GUIDE Apps についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!