Matlab – Use a slider in MATLAB GUI

matlabmatlab-figurematlab-guideslideruser-interface

Really simple question. I wish to create GUI with a simple plot that changes something with a slider. I have been using the GUI and have a slider+text on a panel and axies1. So for starters I just wish to have the slider going from 1:10 (no specific increments) and scaling the y-values (by 1:10). I have imported my data into the GUI, so leaving out the generic auto-generate code I have:

Under Graphslide_OpeningFcn

handles.OutAirTemp = OutAirTemp;
handles.SupAirTemp = SupAirTemp;
guidata(hObject,handles);
handles.a = get(handles.slider2,'Value');
plot(handles.SupAirTemp,handles.a*handles.OutAirTemp)

Under slider2_Callback

a = get(hObject,'Value')

So clearly I am missing something! Any pointers, theory or code will be greatly received.

Edit1
There was no error message for the above. It however didn't change the graph when sliding the slider.

Best Solution

You don't say what error message you get or what the problem is, so we can't guess what's wrong. However, there are a few things I can see are wrong:

  • you probably need to specify the handle of the axes on which to plot when issuing the plot command
  • for your slider2_Callback, you probably need

    handles.a = get(hObject,'Value') guidata(hObject,handles);

  • for your Graphslide_OpeningFcn, you don't say where OutAirTemp and SupAirTemp come from. I would also issue the guidata at the end of the function rather than in the middle as your are doing.

Related Question