Borrar filtros
Borrar filtros

Numbers in a editbox to the workspace

1 visualización (últimos 30 días)
Mikkel
Mikkel el 28 de Jun. de 2012
Hi
I need to make a simple gui that has a editbox and a pushbutton. What I need help with doing, is that when I put a number inside the editbox and presses the pushbutton, then I need the number to be saved on the workspace. fx:
Editbox [ 2 ] [Push button] <-- after pressing that
I want it to say on the workspace: a = 2
And if I change Editbox [ 2 ] to Editbox [ 7 ], then I want the workspace to be updated to say: a = 7.
How do I do that? im quite lost here..

Respuesta aceptada

Sean de Wolski
Sean de Wolski el 28 de Jun. de 2012
Here is a small example:
figure('units','norm');
hE = uicontrol('style','edit','units','norm','position',[.4 .4 .2 .2]);
uicontrol('style','push','units','norm','position',[.1 .1 .1 .1],'string',...
'Save2Workspace','callback',@(src,evt)assignin('base','X',str2double(get(hE,'string'))));
  3 comentarios
Sean de Wolski
Sean de Wolski el 28 de Jun. de 2012
So here's a lesson in good programmign practice:
The edit callback should check to make sure the input is indeed a number.
Something like this:
val = str2double(get(hObject,'string'));
if isnan(val)
errordlg('You entered non numeric input');
end
Then the push button callback would be the equivalent of what I have above translated to guide
assignin('base','X',str2double(get(handles.edit1,'string'))));
Note: there may be typos this isn't tested.
Mikkel
Mikkel el 28 de Jun. de 2012
You are a darling! its just what I needed :) if you are a guru in matlab gui maybe you could help me with my other problem. Have another quition, and some one tryed to anwser it, but it hasent been solved yet. :/

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by