How can I use a slider step to create a graph through a for loop?
조회 수: 3 (최근 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.
댓글 수: 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!