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.

 Akzeptierte Antwort

Amardeep
Amardeep am 26 Okt. 2011

0 Stimmen

Pass the two variables in a handles structure when calling the second window. When the push button in the second window is then clicked call the variables from the handles structure and add them up.

6 Kommentare

SUDIP PODDAR
SUDIP PODDAR am 26 Okt. 2011
I can not understand plz give me the code. plz plz . I am beginner in Guide. Plz help me.
Sean de Wolski
Sean de Wolski am 26 Okt. 2011
Show us what you have done so far. We will not do your homework for you. Amardeep's answer describes roughly what you should be doing. There are also good videos on how to do this in Doug Hull's archive.
http://www.mathworks.com/matlabcentral/fileexchange/8616
SUDIP PODDAR
SUDIP PODDAR am 26 Okt. 2011
plz tell me only the way how i activate the pushbutton of second window by clicking the pushbutton of the first window. plz tell me this one. I need it.
Sean de Wolski
Sean de Wolski am 26 Okt. 2011
You probably set its 'enable' option to 'on' or 'off'.
SUDIP PODDAR
SUDIP PODDAR am 26 Okt. 2011
enable option is in property inspector. but there is no enable command. I want to activate the pushbutton of second window by clicking the pushbutton of the first window automatically. Activating code must be written in first window pushbutton. plz plz help me.
Sean de Wolski
Sean de Wolski am 26 Okt. 2011
set(GUIHandles.Pushbutton2,'enable','on');
now you just have to name the buttons and handles structures accordingly

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
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
SUDIP PODDAR am 26 Okt. 2011
I name the first window tran1 & second tran2. In tran1 i write in the pushbutton1 callback is
p1=get(handles.edit1,'string')
p2=get(handles.edit2,'string')
tfh=tran2('figure1.fig');
tclusdata=guidata(tfh);
set(tclusdata.edit1,'string',p1);
set(tclusdata.edit2,'string',p2);
set(tclusdata.pushbutton1,'enable','on');
in tran2 window in pushbutton1 callback i write
p12=get(handles.edit1,'string')
p21=get(handles.edit2,'string')
p=p12+p21
set(handles.edit3,'string',p);
but it not works. plz help me. Thank you again.
SUDIP PODDAR
SUDIP PODDAR am 27 Okt. 2011
Plz anyone help me.
Walter Roberson
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
SUDIP PODDAR am 28 Okt. 2011
it gives the following error
??? Error using ==>
guidemfile>@(hObject,eventdata)tran2('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Too many input arguments.
Error in ==> tran1>pushbutton1_Callback at 142
cb(tclusdata.pushbutton1,[],tclusdata);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> tran1 at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==> guidemfile>@(hObject,eventdata)tran1('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
what happend i can not understand. plz help . Thank you again
Walter Roberson
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
SUDIP PODDAR am 28 Okt. 2011
but if i give two input in tran1 then it goes to the tran2 but summation gives wrong result. & the set command is not working in tran2 pushbutton1. what i do. plz tell me. if i place hundred lines of code in tran2 pushbutton1 then will it execute. plz help me. i am in deep trouble. i need your help.
Walter Roberson
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
SUDIP PODDAR am 28 Okt. 2011
I understand. Sorry for my mistake. But if tran2 pushbutton1 contains hundred of codes then all the code will be executed with this process? If tran2 calls another figure window within this hundred of codes then will it works? plz give me ur valuable suggestion. Many Many Thanks for ur feedback. Thanks again .
SUDIP PODDAR
SUDIP PODDAR am 14 Nov. 2011
Sorry for delay
SUDIP PODDAR
SUDIP PODDAR am 14 Nov. 2011
your answer is correct but mistakenly i accept another one. Sorry for that.
Walter Roberson
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Interactive Control and Callbacks finden Sie in Hilfe-Center und File Exchange

Produkte

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by