how to set a default value for the slider?

7 views (last 30 days)
Manoj Kumar
Manoj Kumar on 25 Jul 2014
Edited: Geoff Hayes on 25 Jul 2014
Hi, I use slider for thresholding the image.
I used text box to get the values of both the sliders. The default value for slider("high") is 255. The problem I am facing is when I don't move the slider("high") I am unable to get the value. But when I vary the slider, I could get the value in the text box.
Can you help me in how to assign a default value in the text box even if i do not move the slider("high").
I tried in many ways, but none of them are working.
if length(level2)==255
level2=255;
else
level2=level2;
end
also I tried with
if (nargin==255) || isempty(level2)
level2=255;
else
level2=level2;
end
Any help is appreciated
thanks...

Answers (1)

Geoff Hayes
Geoff Hayes on 25 Jul 2014
Edited: Geoff Hayes on 25 Jul 2014
If your default value for the slider is 255, then why not just set this value in the text box. You could do this in the opening function of your GUID (assuming that you are using GUIDE).
Suppose that slider1 is the name of the slider, text1 is the name of the text box, and myGui is the name of the GUI. Then
function myGui_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for myGui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% get the default value for the slider
defVal = get(handles.slider1,'Value');
% set this value in the text box
set(handles.text1,'String',num2str(defVal));
Try the above and see what happens!

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!