GUI slider only translates point in one direction

1 回表示 (過去 30 日間)
Stephen Purk
Stephen Purk 2020 年 2 月 25 日
編集済み: Cris LaPierre 2020 年 3 月 13 日
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!

回答 (1 件)

Miguel Sanz
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.
  1 件のコメント
Stephen Purk
Stephen Purk 2020 年 2 月 27 日
Thanks! It really does help! Hope you get a good grade, I hear that just handing it in gives you a 50 by default.

サインインしてコメントする。

製品

Community Treasure Hunt

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

Start Hunting!

Translated by