필터 지우기
필터 지우기

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 CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by