Automatic activation of a button
Ältere Kommentare anzeigen
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.
Akzeptierte Antwort
Weitere Antworten (1)
Walter Roberson
am 26 Okt. 2011
1 Stimme
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 Kommentare
SUDIP PODDAR
am 26 Okt. 2011
SUDIP PODDAR
am 27 Okt. 2011
Walter Roberson
am 27 Okt. 2011
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
am 28 Okt. 2011
Walter Roberson
am 28 Okt. 2011
Okay, in that case the code can be simplified to
cb = get(tclusdata.pushbutton1, 'Callback');
cb(tclusdata.pushbutton1,[]);
SUDIP PODDAR
am 28 Okt. 2011
Walter Roberson
am 28 Okt. 2011
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
am 28 Okt. 2011
SUDIP PODDAR
am 14 Nov. 2011
SUDIP PODDAR
am 14 Nov. 2011
Walter Roberson
am 14 Nov. 2011
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.
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!