Pushbutton in GUI

조회 수: 6 (최근 30일)
armin
armin 2011년 7월 18일
댓글: vasantha malairamar 2017년 2월 13일
hi
In my GUI i have 2 pushbutton, How can i recieve an output from number one and use that in number 2???
  댓글 수: 1
Gerd
Gerd 2011년 7월 18일
Hio Armin,
what exactly do you want to do?

댓글을 달려면 로그인하십시오.

채택된 답변

Harry MacDowel
Harry MacDowel 2011년 7월 18일
I do not know whether you refer to the variables which are executed in pushbutton1 to pass it to pushbutton2 or you want to know that pushbutton1 is pushed so you pass something over to pushbutton2. Either way I will provide you simple examples:
To pass the value of a variable calculated in pushbutton1 to pushbutton2, simply use the global command.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global var1;
x = get(input_x.handles,'Value',str2num());
y = get(input_y.handles,'Value',str2num());
var1 = x*y^2;
guidata(hObject,handles);
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global var1;
disp(var1);
guidata(hObject,handles);
If you would like to pass something from pushbutton1 to pushbutton2 when you know pushbutton1 is pushed, simply get the Value from the pushbutton while globalizing the variables you want to pass:-
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global var1;
x = get(input_x.handles,'Value',str2num());
y = get(input_y.handles,'Value',str2num());
var1 = x*y^2;
guidata(hObject,handles);
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global var1;
if get(handles.pushbutton1,'Value')
disp(var1);
end
guidata(hObject,handles);
There you go. Try to phrase your questions in a more detailed manner next time.
  댓글 수: 1
vasantha malairamar
vasantha malairamar 2017년 2월 13일
Tnk u.....It works for me.....

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Onur Öçalan
Onur Öçalan 2011년 7월 18일
In pushbutton1...
handles.var1 = output1_frompushbutton1;
In pushbutton2...
You can use your variable "handles.var1".
Don't forget to add end of the function
guidata(handles,hObject);
This updates the handles...

Surendhra Goli
Surendhra Goli 2014년 1월 22일
HI
I have four PUSHBUTTONS.
Each calling one one function like reading inout, Denoising Filtering, Find Peaks
How to make a sequence that is Pushbutton1 output is Input of Pushbutton2... Fallows
Please Guide me How to read input and continue same input as for all program
rggards surendra

카테고리

Help CenterFile Exchange에서 Solver Outputs and Iterative Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by