Transfer function display works in command window but not published file

15 views (last 30 days)
Hello,
I just ran my script file for my transfer function and it worked out just fine in the command window, now when I publish I get an error
syms T Tj I Fj Tj_in
V = 50; % cm^3
R = .05; % ohms
Vj = 30; % cm^3
DeltaH = 15000; % J/C
cp = 2.7778e-4; % Wh/g K
cp_f = 9.7694e-4; % Wh/g K
U = 12.5e-4; % W/cm^2 K
Area = 30; % cm^2
rho = 1.8; % g/cm^3
rho_f = 1.07; % g/cm^3
x = [Tj T];
u = [I Fj Tj_in];
y = x;
f1 = Fj/Vj*(Tj_in-Tj)+(U*Area/(rho_f*cp_f*Vj))*(T-Tj);
f2 = I^2*R/(rho*cp*V)+I*DeltaH*exp(-4000/(273+T))-(U*Area/(rho*cp*V))*(T-Tj);
dx = [f1; f2];
A = jacobian(dx,x);
B = jacobian(dx,u);
C = jacobian(y,x);
D = jacobian(y,u);
Fj_ss = 108; % cm^3/hr
I_ss = 3; % A
Tj_in_ss = 25; % C
T_ss = 46.93; % C
Tj_ss = 30.47; % C
A_substitute = subs(A,{Fj,I,Tj_in,T,Tj},{Fj_ss,I_ss,Tj_in_ss,T_ss,Tj_ss});
B_substitute = subs(B,{Fj,I,Tj_in,T,Tj},{Fj_ss,I_ss,Tj_in_ss,T_ss,Tj_ss});
Anum = eval(A_substitute);
Bnum = eval(B_substitute);
Cnum = eval(C);
Dnum = eval(D);
% State Space Model
sys = ss(Anum,Bnum,Cnum,Dnum)
%%part d
tf = tf(sys)
tf =
From input 1 to output...
14.42
1: ---------------------
s^2 + 6.289 s + 5.369
12.06 s + 57.82
2: ---------------------
s^2 + 6.289 s + 5.369
From input 2 to output...
-0.1823 s - 0.2723
1: ---------------------
s^2 + 6.289 s + 5.369
-0.2735
2: ---------------------
s^2 + 6.289 s + 5.369
From input 3 to output...
3.6 s + 5.376
1: ---------------------
s^2 + 6.289 s + 5.369
5.4
2: ---------------------
s^2 + 6.289 s + 5.369
Continuous-time transfer function.
But now I go into my published file and this comes up
Error using InputOutputModel/subsref (line 44)
Use two or more subscripts to index into MIMO models or model arrays, as in the "sys(2,1)" command.
Error in HW06_Tu_Hamlin_R (line 83)
tf = tf(sys)
And whenever I run that section with the tf (part d), I get the error
Error using InputOutputModel/subsref (line 44)
Use two or more subscripts to index into MIMO models or
model arrays, as in the "sys(2,1)" command.
Why did it work when I clear all contents and run it, but will not work after the first run?
  1 Comment
Rick
Rick on 7 Oct 2015
When I switched the name from tf to transfer_function, that seems to have fixed it, but I wonder why?

Sign in to comment.

Accepted Answer

Steven Lord
Steven Lord on 7 Oct 2015
The first time you executed this script file, MATLAB evaluated the tf function and stored the output from that in the variable named tf.
The second time you executed the script file, MATLAB interpreted "tf = tf(sys)" as an attempt to index into the variable named tf (that you created the first time) and store the result of that indexing into the variable named tf. But you can't index into the object stored in the tf variable that way, so MATLAB threw an error describing how it expected you to index into that object.
When you renamed the variable, both times you executed the script file MATLAB evaluated the tf function and stored the return value in the variable named transfer_function.
You would have received the same type of error if you'd executed:
sin = sin(pi);
The second time you executed that line, MATLAB would indicate that subscript indices must be real positive integers or logicals.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!