Error while using lsim function

5 views (last 30 days)
Ashwini Ananthan
Ashwini Ananthan on 9 Sep 2015
Answered: Matt Cohen on 11 Sep 2015
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) .

Answers (1)

Matt Cohen
Matt Cohen on 11 Sep 2015
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

Tags

Community Treasure Hunt

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

Start Hunting!