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

1 view (last 30 days)
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

Answers (1)

Walter Roberson
Walter Roberson on 15 Aug 2015
  1 Comment
Harjinder Singh Pabla
Harjinder Singh Pabla on 15 Aug 2015
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));

Sign in to comment.

Categories

Find more on Characters and Strings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!