MATLAB: Error when trying to obtain transfer function from MIMO state-space representation in MATLAB

MATLABtransfer function

i'm trying to obtain a transfer function from my state-space MIMO response system. However, when I go to run this code, it will give me:
Error using ss2tf (line 26). The A and B matrices must have the same number of rows.
This doesn't make sense as I have 4 rows in A, and 4 rows in B.
A = [0 2 5 -4;0 0 0 0;0 0 0 1;-6 0 -1 -2]; B = [1 2;0 0;0 0;0 5]'; C = [1 0 0 0;0 1 0 0;0 0 1 0; 0 0 0 1]; D = 0;
[nom1, denom1] = ss2tf(A,B,C,D)

Best Answer

You put an ' sign to your B matrix, therefore with this sign, it contains 2 rows and it gives error. But changing it will not be enough since your D matrix is entered wrong. You should also change it. Lastly, since you have 2 inputs, you also should use ss2tf differently. The resulting code:
A = [0 2 5 -4;0 0 0 0;0 0 0 1;-6 0 -1 -2];
B = [1 2;0 0;0 0;0 5];
C = [1 0 0 0;0 1 0 0;0 0 1 0; 0 0 0 1];
D = zeros(4,2);
[nom1, denom1] = ss2tf(A,B,C,D,1);% for the first input, I wrote 1. You can change it and write 2.
As a result, you have 2 inputs, 4 outputs. You will obtain 8 transfer functions, 4 for each input.