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

 Akzeptierte Antwort

Venkat Ta
Venkat Ta am 14 Jan. 2019

0 Stimmen

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 Kommentare

TADA
TADA am 14 Jan. 2019
like the error implies you can't have both functions with and end statement and functions without end statement in the same file.
So either add end statement to all your functions or remove it from these functions...
since you can have functions declared within other functions, it's much clearer where a function starts and ends with the end phrase...
Venkat Ta
Venkat Ta am 14 Jan. 2019
Thanks a lot. It works
One more question.
How I use that varaible in other function? do I need to declare some where in other function?
I want to use in button function that slider varaible (slider_1_Val), I tried in below code but that doesnot work
% --- Executes on button press in button1.
function button1_Callback(hObject, eventdata, handles)
M=str2num(get(handles.slider_1_Val,'string'));
add = M +100;
set(handles.text2,'string', add)
TADA
TADA am 14 Jan. 2019
you didn't assign the value of the slider into the handles struct, you assigned it into a variable named slider_1_Val in the base wokspace
you can either get that value from the base workspace using
value = evalin('base', 'slider_1_Val');
or better yet, stop using assignin and start saving it in the handles struct like you wanted
just remember that handles is a struct, which means its a value type and not a handle
so when you update it it is only updated in the local workspace. To overcome this, you also have to update the saved reference using guidata:
guidata(hObject, handles);
where hObject is one of the gui components, i.e the slider or the button
Venkat Ta
Venkat Ta am 14 Jan. 2019
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 am 15 Jan. 2019
I Don't Understand What You Are Trying To Achieve And What Isn't Working Well.
Please Be More Specific

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

TADA
TADA am 13 Jan. 2019

0 Stimmen

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

Kategorien

Produkte

Version

R2018a

Gefragt:

am 12 Jan. 2019

Kommentiert:

am 15 Jan. 2019

Community Treasure Hunt

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

Start Hunting!

Translated by