Create a slider in GUI?

2 Ansichten (letzte 30 Tage)
kelly123
kelly123 am 6 Dez. 2015
Kommentiert: Adam am 28 Jul. 2016
Hi,
I'm experimenting with GUIDE and was wondering how to create a slider that allows the user to fix the threshold value from 0 - 255 of an image.
% --- Executes on slider movement.
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
global grayImage;
thresholdValue = uint8(get(handles.sldThreshold, 'Value'));
binaryImage= grayImage > thresholdValue;
axes(handles.axes2);
  3 Kommentare
kelly123
kelly123 am 6 Dez. 2015
It returns:
Undefined variable "handles" or function "handles.slider1".
Varian Adisuryo
Varian Adisuryo am 28 Jul. 2016
same here. I have the same eror. what should I do?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Image Analyst
Image Analyst am 6 Dez. 2015
After the call to axes() in slider1_Callback, you need to call
imshow(binaryImage);
  9 Kommentare
Varian Adisuryo
Varian Adisuryo am 28 Jul. 2016
I just did what you told, but when I run it the slider doesn't show and it become like this: Warning: slider control can not have a Value outside of Min/Max range Control will not be rendered until all of its parameter values are valid
what should I do? please help. I've been struggling with this slider for 3 days :(
Adam
Adam am 28 Jul. 2016
You can set the min, max and value all in a single set command if you want e.g.
set( handles.slider1, 'Min', 0, 'Max', 10, 'Value', 5 )
to make sure that the value is always within the min to max range and avoid getting that warning. The warning is pretty self-explanatory though from the point of view of knowing what is wrong.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Help Center und File Exchange

Tags

Noch keine Tags eingegeben.

Community Treasure Hunt

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

Start Hunting!

Translated by