2

I'm trying to create a GUI with a plot and a slider. The slider should be continuously outputting as described here and here and here. The problem I'm having with these explanations is that the uicontrol object is created programatically. In contrast, I'd like to know what can be added to the GUIDE created .m-file to accomplish the same thing as is done programatically in the previous three examples. The code is below, and I've flagged the (wrong) code that is provided by some of the examples above. Thanks very much for any help!

%this runs the slider

function P1_slider_Callback(hObject, eventdata, handles)
set(handles.P1val, 'String', num2str(get(hObject,'Value'), 3))
PlottheData_Callback(hObject, eventdata, handles) 
    %"PlottheData" is a button that plots data depending on the value of P1_slider

%this creates the slider, and I guess the "making continuous" needs to happen here

function P1_slider_CreateFcn(hObject, eventdata, handles)
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor',[.9 .9 .9]);
%BEGIN WRONG CODE! HELP HERE PLEASE!
    jScrollBar = findjobj(hObject);
    jScrollBar.AdjustmentValueChangedCallback = @myCbFcn;
    hhSlider = handle(hObject);
    hProp = findprop(hhSlider,'Value');  % a schema.prop object
    hListener = handle.listener(hhSlider,hProp,'PropertyPostSet',@myCbFcn);
    setappdata(hhSlider,'sliderListener',hListener);  % this is important - read above
end

The lines between %BEGIN and end are where I'm having trouble. The error message I get is

??? Undefined function or method 'findjobj' for input arguments of type 'double'.
Error in ==> first>P1_slider_CreateFcn at 204
    jScrollBar = findjobj(hObject);
Community
  • 1
  • 1
josh_m
  • 21
  • 3
  • `findjobj` does not ship with Matlab as it is a 3rd party function... try `exist(findjobj)` if equal to zero (false) go to [the file exchange](http://www.mathworks.com/matlabcentral/fileexchange/14317-findjobj-find-java-handles-of-matlab-graphic-objects) to download it. If you have already downloaded make sure it visible to Matlab (on path or in current directly) – RTL Apr 28 '14 at 13:08
  • Whist my previous comment addresses the error your receiving you have two diffrent methods to do the same thing in your code, the `handle.listener` method and `adjustmentvalucechangedCallback` method should both do the same thing , having both seems unnecessary... I suggest going back to the first link you posted where they are presented as two possible methods to do this – RTL Apr 28 '14 at 13:18
  • @RTL, thanks for your comments, but I'm still confused. I downloaded `findjobj` package from FileExchange, and put it into my working directory - no success. Problem now is that `myCbFcn` is undefined. Where should I define this? [Here](http://undocumentedmatlab.com/blog/continuous-slider-callback) on April 11, 2010 there was a discussion about how to proceed inside a GUI created by GUIDE. I have tried to put the `hlistener` commands in the `FILE_OpeningFcn` function, and just the two `jscrollbar` commands in the `P1_slider_CreateFcn` function. Thanks! – josh_m Apr 28 '14 at 19:40
  • Firstly `@myCbFcn` is a function handle to your callback function (in the post you got this from this has been named `myCbFcn`), this is the function that runs when the slider value is changed. To use the callback the slider already has replace it with `@(hObject, eventdata, handles) P1_slider_Callback(hObject, eventdata, handles)` . Secondly you **don't** need to use `handle.listener` if you are using `AdjustmentValueChangedCallback` either one or the other should suffice – RTL Apr 29 '14 at 09:06

0 Answers0