MATLAB Answers


Why slider is not working in my GUI?

Asked by Stelios Fanourakis on 10 Jun 2018
Latest activity Commented on by Stelios Fanourakis on 17 Jun 2018
Accepted Answer by Jan
I have created a GUI consisted of 4 axes, a push button and a slider. Although, the slider commands (callbacks, uicontrols, guidata etc) including the mouseScroll function, are perfectly working, because they have been tested to a different figure (not my GUI) consisted of a single hFig and an axes1 and it perfectly work, but when I try to implement the same commands to my GUI it fails.
You will notice to the m files I attach, that I have placed the same commands over and over again to almost all the relative callback functions (slider1_Callback, mouseScroll, loadButton, etc) because they were asking for the variables to be stated.
Any help on this?

  1 Comment

The slider is not working. It won't move either under wheel scrolling or arrowheads pressing. If it slightly moves, it goes back to the beggining instantly and it won't control the image depicted on the first axes1, it won't alter.

Sign in to comment.

1 Answer

Answer by Jan
on 11 Jun 2018
 Accepted Answer

You are creating a new slider inside the callback of the slider:
handles.SliderFrame = uicontrol('Style','slider','Position',[60 20 400 50], ...
'Min',1,'Max',NumFrames,'Value',1, ...
'SliderStep',[1/NumFrames 2/NumFrames], ...
This hides the formerly existing sliders and sets the slider value to 1 for each call.
Importing the list of files in all slider callbacks is a waste of time in addition.
Solution: Create the slider once only, either in GUIDE or in the OutputFcn (where it is done now already also). Then omit the re-creation by uicontrol.
I suggest to call the slider1_callback from the mouseScroll function.


@Stelios: Are you aware that I spend some time with trying to help you? You repeatedly ignore some of my questions for clarifications. Solving the actual problem would be most likely solved in a minute, if you post the required details.
I cannot open your fig file, because I do not have a Matlab version currently. I cannot imagine what "one up and one down" means. You have created one slider in the OpeningFcn and I see one callback for a slider also. You use the 'Value' property of one uicontrol only. So what it the job of the 2nd slider?
As far as I can see, you define the folder to read from in the OpeningFcn and in the Slider1_callback again.
This is the 25th comment. I strongly recommend to start to use the debugger. This is ways easier than posting some partial descriptions and waiting for the forum to guess the reasons of the problems. I will leave this discussion now, because it is obvious, that I cannot help you efficiently.
Good luck!
@Jan. You do helping me a lot with your suggestions. It seems I need to keep on forward myself from now and on. One slider I added on the GUIDE and one slider from uicontrol. When the figure is loading, it shows 2 sliders but only one of them actually works.
Now the bottom slider works but it works to infinity. I want the total range of the slider to be the number of image frames, e.g. 15
Debugger will only tell me the error point. It won't solve it.

Sign in to comment.