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
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