Problem with using lsim which lead to row and column error ?
1 view (last 30 days)
Show older comments
Upon running my code which is :
A = [0,1;0,0]; B2 = [0;64013000]; Cc = [-10.588174398921385,-0.318818010164237]; Bc = [2.409919108480979e3;4.696699700129756e2]; C2 = [1,0]; Ac = [-2.409587000245264e3,1.000000016273038;-6.777812774681246e8,-2.040849728464332e7];
B1 = [0,0;1,0]; D21 = [0,1];
C1 = [1,0;0,0]; D12 = [0;0.100000000000000];
Acl = [A B2*Cc ; Bc*C2 Ac]; Bcl = [B1 ; Bc*D21]; Ccl = [C1 D12*Cc]; Dcl = zeros(2,2);
clsys = ss(Acl, Bcl, Ccl, Dcl);
t = 0:0.01:10; w = zeros(1, length(t)); k = 1;
for n = 1:length(t) if k < 100 w(k) = 0; elseif k >= 100&&k <= 301; w(k) = 1; else w(k) = 0; end k = k+1; end
y = lsim(clsys, w, t); plot (t, y(1));
I ran into this error: "When simulating the response to a specific input signal, the input data U must be a matrix with as many rows as samples in the time vector T, and as many columns as input channels."
My w and t were clearly having the same row and column as indicated on the workspace. May I know what went wrong?
0 Comments
Accepted Answer
Mischa Kim
on 13 Oct 2014
Hello Raymond, your system has two inputs, therefore w needs to be a 2-by-n array, rather than a 1-by-n. Use instead:
...
t = 0:0.01:10;
w = zeros(2, length(t));
k = 1;
for n = 1:length(t)
if k < 100
w(:,k) = 0;
elseif k >= 100&&k <= 301;
w(:,k) = 1;
else w(:,k) = 0;
end
k = k+1;
end
y = lsim(clsys, w, t);
plot (t, y);
...and adapt to your needs as necessary.
More Answers (0)
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!