フィルターのクリア

Numbers in a editbox to the workspace

1 回表示 (過去 30 日間)
Mikkel
Mikkel 2012 年 6 月 28 日
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..

採用された回答

Sean de Wolski
Sean de Wolski 2012 年 6 月 28 日
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 件のコメント
Sean de Wolski
Sean de Wolski 2012 年 6 月 28 日
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 2012 年 6 月 28 日
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. :/

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by