Error: Subscript indices must either be real positive integers or logicals.
1 view (last 30 days)
Show older comments
In code below, I get error "Subscript indices must either be real positive integers or logicals." when I run MAIN CODE from command line of customrlc(1,2,3). However, when I just run from command line this code:
%R=1;L=2e-3;C=3e-6;
G = tf([1/(L*C)],[1 R/L 1/(L*C)])
bode(G), grid
It works. I'm not sure what is causing the error, any thoughts? Thanks.
MAIN CODE
function customrlc(R,L,C)
close all
%clear all
%clc
A = [0 1/C; -1/L -R/L];
B = [0; 1/L];
Cc = [1 -1];
D = [0];
%Create a Matlab state-space model.
sys = ss(A, B, Cc, D);
close 'all';
%Compute and plot the step response.
%figure;
[y, t] = step(sys);
subplot(2,2,1)
plot(t, y);
grid
xlabel('Time (sec)');
ylabel('Amplitude ');
title('Step Response');
%Compute and plot the impulse response.
%figure;
[y, t] = impulse(sys);
subplot(2,2,2)
plot(t, y);
grid
xlabel('Time (sec)');
ylabel('Amplitude ');
title('Impulse Response');
%Compute and plot the zero-state response to a sinusoidal input.
%figure;
dt = 0.002;
tf = 4;
t = 0 : dt : tf;
u = sin(t);
[ysine, t] = lsim(sys, u, t);
subplot(2,2,3)
plot(t, ysine);
grid
xlabel('Time (sec)');
ylabel('Amplitude ');
title('Sine Response');
%bode response
hold on
figure
%R=1;L=2e-3;C=3e-6;
G = tf([1/(L*C)],[1 R/L 1/(L*C)])
bode(G), grid
end
2 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Plot Customization 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!