GUI slider only translates point in one direction
1 次查看(过去 30 天)
显示 更早的评论
Hello,
So I created a code that makes 2 sliders translate a point on an axis in the x and y direction. But either way I pull the sliders, they go ONLY in the positive direction. Can anyone help me corredct this?
Code:
function x_pos_Callback(hObject, eventdata, handles)
% hObject handle to x_pos (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
global pnt
global Npnt
cla
x = get(hObject,'Value');
pnt(:,1) = pnt(:,1)+x;
pnt(Npnt+1:end,:) =[];
patch(pnt(:,1),pnt(:,2),'r')
% --- Executes during object creation, after setting all properties.
function x_pos_CreateFcn(hObject, eventdata, handles)
% hObject handle to x_pos (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]);
end
Thankyou to anyone who reads this!
0 个评论
回答(1 个)
Miguel Sanz
2020-2-27
I am also in your class. What you want to do is go to the actual GUI (guide) and go to the slider's propert inspector. Once there, there are min and max limits; simply put the min at -1.
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!