Automatic activation of a button
이전 댓글 표시
Hi Thanks for your reply. I am using guide. I have two gui figure window. In the first window i have two edit box & a pushbutton. In second window I have an edit box & a pushbutton. From first window i want to take two input through edit box. In the second window I want to disply the summation of these two in the edit box of second window, after pressing the pushbutton of the first window. The summation funtion is written in the pushbutton of the second window. I want to activate the pushbutton of second window automatically by pressing the pushbutton of first window. How i do that. Plz plz help me. Thanks again.
채택된 답변
추가 답변 (1개)
Walter Roberson
2011년 10월 26일
1 개 추천
The earlier responses will not accomplish what you are trying to do.
In order to activate (that is, execute) the callback of the second pushbutton when you press the first, you need to get the handle of the second pushbutton, and you need to get() the Callback of that pushbutton, and then you have to invoke that callback.
The exact mechanisms for invoking the callback once you have found it, varies according to how the callback was coded. If the callback was coded as a string (as tends to be the case when you use GUIDE) then you should use eval() to execute the string.
댓글 수: 11
SUDIP PODDAR
2011년 10월 26일
SUDIP PODDAR
2011년 10월 27일
Walter Roberson
2011년 10월 27일
If you want the tran1 pushbutton callback to execute (not just enable!) tran2's pushbutton1 callback, then in the tran1 pushbutton callback, add
cb = get(tclusdata.pushbutton1, 'Callback');
if ischar(cb) %character string was supplied
eval(cb)
elseif iscell(cb) %function cell was supplied
cb{1}(tclusdata.pushbutton1,[],cb{2:end});
else %function handle was supplied
cb(tclusdata.pusbutton1,[],tclusdata);
end
SUDIP PODDAR
2011년 10월 28일
Walter Roberson
2011년 10월 28일
Okay, in that case the code can be simplified to
cb = get(tclusdata.pushbutton1, 'Callback');
cb(tclusdata.pushbutton1,[]);
SUDIP PODDAR
2011년 10월 28일
Walter Roberson
2011년 10월 28일
Here is something for you to try:
char('1' + '1')
What value does it give? Is it the value you expect?
What is the difference between
'1' + '1'
and
1 + 1
??
When you retrieve the 'String' property of edit1, do you get '1' or do you get 1 ?
SUDIP PODDAR
2011년 10월 28일
SUDIP PODDAR
2011년 11월 14일
SUDIP PODDAR
2011년 11월 14일
Walter Roberson
2011년 11월 14일
If you get() the callback and execute it in the manner I showed, then *all* appropriate parts of the callback will be executed. It would be tricky (but not impossible) for the callback to detect that it was being executed indirectly instead of directly because that button itself had been pushed.
카테고리
도움말 센터 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!