Getting a variable from an Edit box, using a push button.

2 次查看(过去 30 天)
Hello all, I am fairly new to matlab and I have a bit of a snafu.
I have a snippet of code that relies on pulling someones age from a edit box, and placing it in a variable. I put the callback that triggers it in the push button.
This is my code.
function AgeEdit_Callback(hObject, eventdata, handles)
code that doesn't matter.. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function AgePushButton_Callback(hObject, eventdata, handles)
age = str2double(get(handles.AgeEdit , 'String'));
My issue that Im encountering is that when i type in a value into the age edit box, then hit the button, no variable pops up in my workspace and i also get no errors. I am genuinely stumped. Any and all ideas are welcome.

采纳的回答

CS Researcher
CS Researcher 2016-5-1
It will not go to your workspace directly. To save the value to the workspace do this:
age = str2double(get(handles.AgeEdit , 'String'));
assignin('base','age',age);
Then you go to the workspace and use the age variable.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by