GUI slider problem in edit_text
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Venkat Ta
el 12 de En. de 2019
Comentada: TADA
el 15 de En. de 2019
Hi,
I have the issue in the slider with edit_text in GUI
When I fix the value in edit text, the slider moves but it doesnot update the slider variable until I touch the slider cursor. I nedd to use only one variable at fixing the value in edit_text as well as moving cursor automatically
Can you help in the below code
Best regards,
Venkat
0 comentarios
Respuesta aceptada
Más respuestas (1)
TADA
el 13 de En. de 2019
you can add a utility function that takes in the new value and sets it in the appropriate variable, and gets a list of controls to update...
something like that:
function onValueChanged(value, varName, updateGuiHandles)
assignin('base', varName ,value);
% lets assume updateGuiHandles is a cell array here
for i = 1:length(updateGuiHandles)
uih = updateGuiHandles{i};
switch get(uih, 'Style')
case {'edit'} % maybe others too
if ~ischar(value)
v = num2str(value);
else
v = value;
end
set(uih, 'String', v);
case {'slider'} % maybe others too
if ischar(value)
v = str2double(value);
else
v = value;
end
set(uih, 'Value', v);
end
end
end
function onSliderValueUpdated(value, updateGuiHandles)
onValueChanged(value, 'slider_1_Val', updateGuiHandles);
end
now call that from your callback function:
function edit1_Callback(hObject, eventdata, handles)
edit1_value=get(hObject,'String');
onSliderValueUpdated(edit1_value, {handles.slider1});
end
function slider1_Callback(hObject, eventdata, handles)
slider1Value = get(handles.slider1,'Value');
onSliderValueUpdated(slider1Value, {handles.edit1});
end
0 comentarios
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!