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 onfigure%R=1;L=2e-3;C=3e-6;G = tf([1/(L*C)],[1 R/L 1/(L*C)])bode(G), gridend
Best Answer