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

2 vues (au cours des 30 derniers jours)
Elie Younes
Elie Younes le 1 Mai 2016
Commenté : Elie Younes le 1 Mai 2016
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.

Réponse acceptée

CS Researcher
CS Researcher le 1 Mai 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.

Plus de réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by