필터 지우기
필터 지우기

How to evaluate calback function in edit text uicontrol?

조회 수: 9 (최근 30일)
Imo
Imo 2012년 10월 19일
I have just started to learn about low-level GUI programing.
Is this the right way to write code. I need my variable b to change every time i hit new entry into edit text but I'm not geting that.
Am I missing evaluate function somewhere?
This is a simple example
fig_h=figure;
callb=['b=get(a,''string'')']
a=uicontrol(fig_h,'Position',[ .5 .5 .08 .06],'Style','edit','CallBack','callb','String','0','Units','normalized');
Thanks

채택된 답변

Matt Fig
Matt Fig 2012년 10월 19일
편집: Matt Fig 2012년 10월 19일
Please do not program callback using strings. Use function handles instead. Save this in an M-file then run the file to see how it works.
function [] = my_gui()
fig_h=figure;
a = uicontrol(fig_h, 'Style','edit',...
'Units','normalized',...
'Position',[.5 .5 .08 .06],...
'CallBack',@callb,...
'String','0');
function [] = callb(H,E)
a = get(H,'string');
disp(['The string in the editbox is: ',a])
Here is a tutorial that starts basic and builds up to more advanced GUIS. I encourage you to work through it.

추가 답변 (2개)

Walter Roberson
Walter Roberson 2012년 10월 19일
Callbacks that are given as strings are executed in the context of the base workspace, so look for b there.

Imo
Imo 2012년 10월 20일
Thanks, I will try that. I guess no one likes the string approach maybe because it is really hard to read. I'm going to study function build. Thanks for the tip and new materials, I appreciate.

카테고리

Help CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by