Error while using lsim function

조회 수: 16 (최근 30일)
Ashwini Ananthan
Ashwini Ananthan 2015년 9월 9일
답변: Matt Cohen 2015년 9월 11일
I am using lsim function and i am getting error saying "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." The command that i used is below u = gensig('square',50,100,1); t = 0:0.1:10; e= [0,1,0;0,0,1;-4,-3,-2]; f= [0,0,1;0,0,0;0,0,0]; g = [1,0,0;0,0,0;0,0,0]; h = [0,0,0;0,0,0;0,0,0]; sys = ss(e,f,g,h); lsim(sys,u,t) .

답변 (1개)

Matt Cohen
Matt Cohen 2015년 9월 11일
Hi Ashwini,
It appears the issue you are having is with the input vector that you are passing into the "lsim" function. When you create the space-space model with the "ss" function, your inputs (e, f, g, and h) specify the number of states (Nx), number of inputs (Nu), and number of outputs (Ny) for the model. Specifically, e is an Nx-by-Nx matrix; f has size Nx-by-Nu; g has size Ny-by-Nx; and h has size Ny-by-Nu. Here, you have specified the model to have 3 inputs, 3 outputs, and 3 states, since all of the input matrices are 3x3. So when you simulate the response of the system to an input, your input's size must satisfy what the model expects.
Here, for your input signal, the number of rows must match the number of time samples (101), and the number of columns must match the number of input channels for the model (3). So make a new input matrix that is 101x3 instead of 101x1 like your input signal 'u' is. You can try something like this:
% Use the square signal in 'u' as the signal for each input channel
U = [u,u,u];
lsim(sys,U,t)
I hope this helps!
Matt

카테고리

Help CenterFile Exchange에서 Nonlinear ARX Models에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by