I would like to know how I could use the the values for one function to another.

조회 수: 1 (최근 30일)
I would like to know how I could use the the values for num, den and sys I have in function untitled_OpeningFcn and use them on the pushbutton1_Callback function for the graphs and setting of the values of the text boxes.
function untitled_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
if strcmp(get(hObject,'Visible'),'off')
t = 0:0.25:7;
y = sin(t);
plot(t,y)
end
num = input('Enter coefficients of numerator: ');
den= input('Enter coefficients of denominator: ');
sys = tf([num],[den]);
display('Your transfer function is: '); sys
function pushbutton1_Callback(hObject, eventdata, handles)
if true
end
axes(handles.axes1);
cla;
set(handles.numtxt, 'String', num2str(num));
set(handles.dentxt, 'String', num2str(den));
popup_sel_index = get(handles.popupmenu1, 'Value');
switch popup_sel_index
case 1
pzmap(sys);
case 2
rlocus(sys);
case 3
nyquist(sys);
case 4
bode(sys);
end

답변 (1개)

Walter Roberson
Walter Roberson 2015년 8월 15일
  댓글 수: 1
Harjinder Singh Pabla
Harjinder Singh Pabla 2015년 8월 15일
I added global num den inside the first function and then I added handles.num and den.
num = input('Enter coefficients of numerator: ');
den = input('Enter coefficients of denominator: ');
sys = tf([num],[den]);
display('Your transfer function is: '); sys
handles.num = num;
handles.den = den;
num = handles.num;
den = handles.den;
sys = tf(num,den);
g = ilaplace(1/s^3);
set(handles.text9, 'String', char(g));
set(handles.numtxt, 'String', num2str(num));
set(handles.dentxt, 'String', num2str(den));

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

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by