GUI slider problem in edit_text

조회 수: 1 (최근 30일)
Venkat Ta
Venkat Ta 2019년 1월 12일
댓글: TADA 2019년 1월 15일
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

채택된 답변

Venkat Ta
Venkat Ta 2019년 1월 14일
Hi,
Thanks for the code but I have error below in the code
Error: File: SliderSIX.m Line: 175 Column: 1
The function "slider1_Callback" was closed with an 'end', but at least one other function definition was not. To avoid confusion when using nested functions, it is illegal to use both conventions in the same file.
  댓글 수: 6
Venkat Ta
Venkat Ta 2019년 1월 14일
Hi,
The base workspace works fine and Thanks for that. The second I dont get it, sorry.
I tried the min, max and fixed value set in slider createfuncton and opening function but it doesnot work well in this format. can you tell me where exactly I can set the min, max and fixed slider value?
TADA
TADA 2019년 1월 15일
I Don't Understand What You Are Trying To Achieve And What Isn't Working Well.
Please Be More Specific

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

TADA
TADA 2019년 1월 13일
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

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by