GUI slider only translates point in one direction

1 Ansicht (letzte 30 Tage)
Stephen Purk
Stephen Purk am 25 Feb. 2020
Bearbeitet: Cris LaPierre am 13 Mär. 2020
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!

Antworten (1)

Miguel Sanz
Miguel Sanz am 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.
  1 Kommentar
Stephen Purk
Stephen Purk am 27 Feb. 2020
Thanks! It really does help! Hope you get a good grade, I hear that just handing it in gives you a 50 by default.

Melden Sie sich an, um zu kommentieren.

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by