Clear Filters
Clear Filters

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

3 views (last 30 days)
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.

Accepted Answer

CS Researcher
CS Researcher on 1 May 2016
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.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!