GUI slider only translates point in one direction
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Miguel Sanz
on 27 Feb 2020
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.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!