Subscript indices must either be real positive integers or logicals.
1 view (last 30 days)
Show older comments
Hi i am getting an error in this MATLAB code and im not sure whats wrong with it. %define verialbe lm=0.01; Rm=0.05; Kt=1.2; Kb=4.0; B=0.25; J=10.0;
%coeff of denominator a0=((Rm/Kt)+Kb);
a1=(lm*B+Rm*J)/Kt;
a2=((lm*J)/Kt);
%define numerator and demenator num=[1]; den=[a2 a1 a0];
%define TF Gopen=tf(num,den)
% step(Gopen)
The error is coming from line 24 which is Gopen=tf(num,den) so can anyone help me.
0 Comments
Accepted Answer
Star Strider
on 13 Apr 2014
I cannot duplicate the error you are getting.
When I run:
%define variable
lm=0.01; Rm=0.05; Kt=1.2; Kb=4.0; B=0.25; J=10.0;
%coeff of denominator
a0=((Rm/Kt)+Kb);
a1=(lm*B+Rm*J)/Kt;
a2=((lm*J)/Kt);
%define numerator and denominator
num=[1];
den=[a2 a1 a0];
%define TF
Gopen=tf(num,den)
produces:
Gopen =
1
------------------------------
0.08333 s^2 + 0.4187 s + 4.042
Continuous-time transfer function.
and:
step(Gopen)
produces:
2 Comments
Star Strider
on 13 Apr 2014
Edited: Star Strider
on 13 Apr 2014
I cannot see where the problem might be in the code you posted, since you defined all your variables, overwriting any that might have existed earlier in your code, and it worked fine for me.
Type this at the Command Window prompt:
which tf -all
On my machine, I get as the result:
C:\Program Files\MATLAB\R2014a\toolbox\control\control\@tf\tf.m % tf constructor
C:\Program Files\MATLAB\R2014a\toolbox\control\control\@DynamicSystem\tf.m % DynamicSystem method
C:\Program Files\MATLAB\R2014a\toolbox\ident\ident\@idParametric\tf.m % idParametric method
C:\Program Files\MATLAB\R2014a\toolbox\shared\controllib\engine\@StaticModel\tf.m % StaticModel method
C:\Program Files\MATLAB\R2014a\toolbox\signal\signal\@dfilt\tf.m % dfilt method
If you get anything else, especially if it’s in your user file directory, you have created a variable named tf (probably an array, possibly a function) that is ‘shadowing’ the built-in MATLAB tf function. You have to rename or delete your ‘shadowing’ array (or function) so the built-in tf function will work correctly.
That’s my best guess. If that doesn’t work, you will have to look for other solutions.
More Answers (1)
Image Analyst
on 13 Apr 2014
Edited: Image Analyst
on 13 Apr 2014
Do you get
Undefined function 'tf' for input arguments of type 'double'.
Error in test3 (line 26)
Gopen=tf(num,den)
If so, you don't have whatever toolbox tf is in. What toolboxes show up when you type ver on the command line? If you're trying to use the one in the Signal Processing Toolbox, it takes only one input argument, not two.
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!