我在MATLAB中显示一个滑块,但是它给出了一个错误
@(hObject,eventdata)rotate('slider1_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback.
这是代码:
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
a=get(handles.slider1,'Min',1,'Max',10,'Value',1);
%// error line:
function slider1_Callback(hObject, eventdata, handles)
答案 0 :(得分:1)
这是错误的:
a=get(handles.slider1,'Min',1,'Max',10,'Value',1);
您可以这样做:
a_min=get(handles.slider1,'Min');
a_max=get(handles.slider1,'Max');
a_val=get(handles.slider1,'Value');
如果您想获取 uicontrol
的属性,或者:
a=set(handles.slider1,'Min',1,'Max',10,'Value',1);
如果您想设置 uicontrol
。
编辑后发表评论:
听起来好像要在编辑文本框中显示滑块的当前值。然后你需要做:
a_val=get(handles.slider1,'Value');
str=sprintf('Slider value %f',a_val);
set(handles.text1,'String',str);
确保你的问题摆好姿势和自足,除非你实际告诉我们,否则我们无法猜测你要做什么。