Create slider with dynamic range based on user input matlab gui -
hi have quick question on how solve issue. take inputs 2 edit text boxes , specify them min , max of sliders range. don't have problem doing min entered slider disappears because min above default slider value, 0. understand error because value no longer in range of min , max, , want fix updating value above min in call function min/max input text boxes. there way can update default value above min can past error , use slider?
warning: 'slider' control cannot have 'value' outside of 'min'-'max' range control not rendered until of parameter values valid
here have tried in call edit box gets user input minimum slider:
function input_min_callback(hobject, eventdata, handles) value_min=str2double(get(hobject, 'string')); if value_min > slidervalue_default set(handles.input_transverse_shear_layer1, 'value', value_min+1); set(handles.input_transverse_shear_layer1, 'min', value_min); end
any appreciated!
thanks
your code looks fine me. seem missing guidata(hobject,handles)
at end update guidata problem (unless it's there did not include in above snippet).
in case here bit of code looks yours , works fine. try out might see wrong yours...
function updateslidermin(~) clc clear close %// create gui elements , set default slide value hfig = figure('position',[200 200 200 300]); slidervalue_default = 0; handles.slider = uicontrol('style', 'slider', 'min', -5, 'max', 10, 'value',slidervalue_default, 'units','normalized','position', [0.08 0.3 0.08 0.6], 'callback', @(s,e) slidercbk); handles.text_min = uicontrol('style','text','string','min','position', [60 230 40 20]); handles.edit_min = uicontrol('style','edit','string',num2str(get(handles.slider,'min')),'position', [100 230 40 20],'callback',@(s,e) mincallback); handles.text_max = uicontrol('style','text','string','max','position', [60 180 40 20]); handles.edit_max = uicontrol('style','edit','string',num2str(get(handles.slider,'max')),'position', [100 180 40 20]); handles.text_val = uicontrol('style','text','string','value','position', [60 130 40 20]); handles.edit_val = uicontrol('style','edit','string',num2str(get(handles.slider,'value')),'position', [100 130 40 20]); guidata(hfig,handles) %// callback of edit box min value function mincallback value_min=str2double(get(handles.edit_min, 'string')); if value_min > slidervalue_default set(handles.slider, 'value', value_min+1); set(handles.slider, 'min', value_min); set(handles.edit_val,'string',get(handles.slider, 'value')); end guidata(hfig,handles) end %// slider callback. check value updated correctly function slidercbk currentvalue = get(handles.slider,'value'); set(handles.edit_val,'string',num2str(currentvalue)); guidata(hfig,handles) end end
screenshot of initial gui:
and after setting minimum value 5, above current value of slider:
the current value updated 6 expected.
hope helps!
Comments
Post a Comment