f

#### Error: Subscript indices must either be real positive integers or logicals.

I keep getting the error "Subscript indices must either be real positive integers or logicals." at the line where I try to define sys...what gives?

% MEEG 4213 HW2.11     February 25, 2011     9:00 pm     R. Leonard
% This program calculates and plots the position of a car and its wheel
%  after the car hits a bump. After looking at graphs with different values
%  of b, it should be clear what a desirable damping coefficient would
%  be to give passengers a smooth ride.

b = input('b value: ');     % Allows user to designate damping coefficient
tf = input('end time: ');   % User-defined end-time of analysis (t0 = 0)
ti = input('time increment: ');     % User-defined time increment (sec)
t = 0:ti:tf;    % Definition of time array, t
m1 = 10;    % Mass 1 is 10 kg
m2 = 350;   % Mass 2 is 350 kg
kw = 500000;    % Spring constant of kw is 500000 N/m
ks = 10000;     % Spring constant of kw is 10000 N/m
num = (kw*b/(m1*m2))*[1 ks/b];    % Numerator of equation 2.12 in book
den = [1 (b/m1+b/m2) (ks/m1+ks/m2+kw/m1) (kw*b)/(m1*m2) kw*ks/(m1*m2)];
% Denominator of equation 2.12 in book...Note s^4 term, s^3 term, s^2 term,
%  s^1 term, and the constant. Spaces separate these terms.
sys = tf(num,den);  % MATLAB required internal definition of the 'system'
y = step(sys, t);   % Returns array data in y for each t value
plot(t, y)  % Plots the results
title('HW2.11 Position of Car and Wheel After Hitting Bump')
xvalue('time (s)')
yvalue('position (m)')
 0
Rebecca
2/27/2011 9:06:29 PM
comp.soft-sys.matlab 211266 articles. 19 followers. lunamoonmoon (257) is leader.

5 Replies
1456 Views

Similar Articles

[PageSpeed] 4

On 2/27/2011 3:06 PM, Rebecca wrote:
> I keep getting the error "Subscript indices must either be real positive
> integers or logicals." at the line where I try to define sys...what gives?
....
> b = input('b value: '); % Allows user to designate damping coefficient
> tf = input('end time: '); % User-defined end-time of analysis (t0 = 0)
....
> sys = tf(num,den); % MATLAB required internal definition of the 'system'
....

You've used tf as a ordinary variable, then either are trying to refer
to an (thereby aliased) function of the same name or a 2D array instead
(which is what Matlab thinks).

Not enough data to tell what you intend but clear what confused Matlab.

--
 0
dpb
2/27/2011 10:14:07 PM
"Rebecca" wrote in message <ikeecl\$r5r\$1@fred.mathworks.com>...
> I keep getting the error "Subscript indices must either be real positive integers or logicals." at the line where I try to define sys...what gives?
>
> % MEEG 4213 HW2.11     February 25, 2011     9:00 pm     R. Leonard
> % This program calculates and plots the position of a car and its wheel
> %  after the car hits a bump. After looking at graphs with different values
> %  of b, it should be clear what a desirable damping coefficient would
> %  be to give passengers a smooth ride.
>
> b = input('b value: ');     % Allows user to designate damping coefficient
> tf = input('end time: ');   % User-defined end-time of analysis (t0 = 0)
> ti = input('time increment: ');     % User-defined time increment (sec)
> t = 0:ti:tf;    % Definition of time array, t
> m1 = 10;    % Mass 1 is 10 kg
> m2 = 350;   % Mass 2 is 350 kg
> kw = 500000;    % Spring constant of kw is 500000 N/m
> ks = 10000;     % Spring constant of kw is 10000 N/m
> num = (kw*b/(m1*m2))*[1 ks/b];    % Numerator of equation 2.12 in book
> den = [1 (b/m1+b/m2) (ks/m1+ks/m2+kw/m1) (kw*b)/(m1*m2) kw*ks/(m1*m2)];
> % Denominator of equation 2.12 in book...Note s^4 term, s^3 term, s^2 term,
> %  s^1 term, and the constant. Spaces separate these terms.
> sys = tf(num,den);  % MATLAB required internal definition of the 'system'
> y = step(sys, t);   % Returns array data in y for each t value
> plot(t, y)  % Plots the results
> title('HW2.11 Position of Car and Wheel After Hitting Bump')
> xvalue('time (s)')
> yvalue('position (m)')
 0
Wayne
2/27/2011 10:21:21 PM
"Rebecca" wrote in message <ikeecl\$r5r\$1@fred.mathworks.com>...
> I keep getting the error "Subscript indices must either be real positive integers or logicals." at the line where I try to define sys...what gives?
>
> % MEEG 4213 HW2.11     February 25, 2011     9:00 pm     R. Leonard
> % This program calculates and plots the position of a car and its wheel
> %  after the car hits a bump. After looking at graphs with different values
> %  of b, it should be clear what a desirable damping coefficient would
> %  be to give passengers a smooth ride.
>
> b = input('b value: ');     % Allows user to designate damping coefficient
> tf = input('end time: ');   % User-defined end-time of analysis (t0 = 0)
> ti = input('time increment: ');     % User-defined time increment (sec)
> t = 0:ti:tf;    % Definition of time array, t
> m1 = 10;    % Mass 1 is 10 kg
> m2 = 350;   % Mass 2 is 350 kg
> kw = 500000;    % Spring constant of kw is 500000 N/m
> ks = 10000;     % Spring constant of kw is 10000 N/m
> num = (kw*b/(m1*m2))*[1 ks/b];    % Numerator of equation 2.12 in book
> den = [1 (b/m1+b/m2) (ks/m1+ks/m2+kw/m1) (kw*b)/(m1*m2) kw*ks/(m1*m2)];
> % Denominator of equation 2.12 in book...Note s^4 term, s^3 term, s^2 term,
> %  s^1 term, and the constant. Spaces separate these terms.
> sys = tf(num,den);  % MATLAB required internal definition of the 'system'
> y = step(sys, t);   % Returns array data in y for each t value
> plot(t, y)  % Plots the results
> title('HW2.11 Position of Car and Wheel After Hitting Bump')
> xvalue('time (s)')
> yvalue('position (m)')

You can't define a variable named tf and then try to call a function tf(). You've defined tf as a scalar.
You should avoid naming variables the same as a MATLAB function, method, object, etc.

Wayne
 0
Wayne
2/27/2011 10:23:05 PM
sorry that book is this equation?

num = (kw * b) / (m1 * m2) * [1 ks / b];
den = [1, (b/m2 b/m1 +), (+ kw/m1 ks/m2 ks/m1 +), (kw * b) / (m1 * m2), (kw * ks) / (m1 * m2)];
 0
William
4/2/2014 3:50:14 PM
sorry that book is this equation?
num = (kw * b) / (m1 * m2) * [1 ks / b];
den = [1, (b/m2 b/m1 +), (+ kw/m1 ks/m2 ks/m1 +), (kw * b) / (m1 * m2), (kw * ks) / (m1 * m2)];
 0
William
4/2/2014 3:55:11 PM
 Reply: