Passing a value from a slider (guide) to a related function
3 次查看(过去 30 天)
显示 更早的评论
I've designed a Gui with Guide. Basically I want to use a slider to define the part of a recorded curve that will be used as a template for a fitting function. The gui is in one .m file and the funciton in another .m file The gui is working fine , the slider adopts correct values. When I want to use this value in the function file I get the message "Not enough input argument". The function start with an (handle) declaration I tried with t=get(handle.slider2,'value') , not wotking , I tried with a combination -setappdat and getappdata-, empty matrix, I tried with findobj(0,'Tag',slider2), empty matrix. I'm kind of stuck here. Any suggestions would be appreciated.
% --- Executes on slider movement.
function slider2_Callback(hObject, eventdata, handles)
% hObject handle to slider2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
slidervalue2=get(hObject,'Value');
set(handles.text4,'String',num2str(slidervalue2))
%setappdata(hObject,'Valueslider2',slidervalue2);
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
% --- Executes during object creation, after setting all properties.
function slider2_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
function fitsinglebeat (handles)
pressure=getappdata(0,'pressure')
T=numel(pressure)
tsyst0=0
%sl1=findobj(0,'Tag','slider2')
tsyst1=get(handles.slider2,'value')
%tsyst1=getappdata(0,'valueslider2')
0 个评论
回答(1 个)
Adam
2016-12-19
You aren't calling your fitsinglebeat function anywhere, but don't pass handles to it. If you want a single value from your slider then just pass this to it, not a whole structure full of things you don't want.
function fitsinglebeat ( value ) pressure=getappdata(0,'pressure') T=numel(pressure) tsyst0=0 tsyst1=value;
and just call it from your slider callback as
fitsinglebeat ( hObject.Value )
or
fitsinglebeat ( get( hObject, 'Value' ) ) % Pre R2014b
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!