Copilot gives directions on using ARX to identify a MIMO model which do not work - what is the correct call to ARX for 5 input, 3 output system?

I have an iddata dataset "data_d" which contains ~5000 samples with 5 inputs and 3 outputs.
I asked Copilot for advice on using ARX to model: "for my dataset data_d which has 3 outputs and 5 inputs, use the arx function to estimate a MIMO model"
Copilot suggested this code:
% Example orders
na = 2; % A-order (can be scalar or 1-by-Ny)
nb = 2*ones(1,5); % B-orders: 1-by-Nu applies to all outputs
nk = 1*ones(1,5); % Input delays (samples): 1-by-Nu applies to all outputs
% Estimate MIMO ARX
sys_arx = arx(data_d, [na nb nk]);
However when running this I get the error message:
Error using arx (line 135)
The model order matrices must have as many rows as there are outputs in the data.
With nb and nk being rows I tried transposing them to columns and excuting the arx function call again... this time gives message
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Having told Copilot the code above didn't work, it suggested this - which also didn't work, with error message:
The model orders must be compatible with the input and output dimensions of the estimation data. Type "help arx" for
more information.
Ny = 3;
Nu = 5;
% Per-output A-orders
na_vec = [2 2 2]; % 1-by-Ny
% Per-output/input B-orders and delays (Ny-by-Nu)
nb_mat = 2 * ones(Ny, Nu); % each output has nb=2 for every input
nk_mat = 1 * ones(Ny, Nu); % each output has nk=1 for every input
% Build orders matrix: each row = [na_i nb_row(1:Nu) nk_row(1:Nu)]
orders = zeros(Ny, 1 + Nu + Nu);
for i = 1:Ny
orders(i,:) = [na_vec(i), nb_mat(i,:), nk_mat(i,:)];
end
sys_arx = arx(data_d, orders);
What is the correct call to ARX for a 5 input 3 output system?

 Accepted Answer

This is what the Matlab support team gave me. It works
na = 2*ones(3,3); % Assume each output depends on the previous 2 samples of every output (including itself)
nb = 2*ones(3,5); % Assume each output depends on the previous 2 samples of every input
nk = ones(3,5); % Assume each input affects each output after a delay of 1 sample
model_arx = arx(data_d, [na nb nk]);

More Answers (1)

Hi @Sean,
Thanks for reaching out about the ARX estimation error with your 5-input, 3-output system. I've reviewed the MathWorks documentation thoroughly and the issue is clear - for MIMO (multiple-input, multiple-output) ARX models, the order matrices na, nb, and nk must have one row per output, not one column or scalar values because according to the official ARX documentation, for a system with Ny outputs and Nu inputs, na must be an Ny-by-Ny matrix of nonnegative integers specifying the order of the A polynomial for each output, nb must be an Ny-by-Nu matrix specifying the order of the B polynomial plus one for each output-input pair, and nk must be an Ny-by-Nu matrix specifying the input-output delay in samples for each output-input pair, so for your specific case with 3 outputs and 5 inputs the correct syntax is:
Please see attached.
The key point is that na must be either a scalar (for single-output systems) or an Ny-by-1 column vector where each element specifies the A-polynomial order for the corresponding output, and both nb and nk must be Ny-by-Nu matrices where each row corresponds to one output and specifies the B-polynomial orders and delays for all inputs affecting that output. The error message "The model order matrices must have as many rows as there are outputs in the data" is telling you exactly this - you need 3 rows in your order specification, one for each output. If you want different orders for different outputs, you can specify them individually, for example na = [2; 3; 2] would give the first output an A-order of 2, the second output an A-order of 3, and the third output an A-order of 2, and similarly you could vary the nb and nk values across different output-input pairs if needed, but for simplicity starting with uniform orders like 2*ones(3,5) is perfectly fine. One additional note - the ARX function minimizes the trace of the prediction error covariance matrix for MIMO systems, and if you want to weight the outputs differently you can use the OutputWeight option in arxOptions to specify a weighting matrix. Also, make sure your data_d iddata object is correctly formatted with 5 input channels and 3 output channels, which you can verify by checking data_d.Nu and data_d.Ny properties. The final working code for your case is exactly as shown above with the na as a 3x1 column vector and nb and nk as 3x5 matrices, and this should estimate your MIMO ARX model without errors.
Hope this helps!

3 Comments

Thanks for the input. The code example you sent didn't work either... here's the output with the error message I've ran in to so many times:
>> Ny=3; Nu=5;
>> na=[2;2;2]
na =
2
2
2
>> nb=2*ones(Ny,Nu)
nb =
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
>> nk=ones(Ny,Nu)
nk =
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
>> sys_arx=arx(data_d,[na nb nk]);
Error using arx (line 135)
The model orders must be compatible with the input and output dimensions of the estimation data. Type "help arx" for more information.
I had a similar answer directly from the Matlab support team with working na, nb, nk matrices to allow me to run my arx model.
Their answer set
na = 2*ones(3,3); % Assume each output depends on the previous 2 samples of every output (including itself)
nb = 2*ones(3,5); % Assume each output depends on the previous 2 samples of every input
nk = ones(3,5); % Assume each input affects each output after a delay of 1 sample
This answer - which does work - is subtly different, it's just the na matrix which is different, being a matrix of 2s rather a single vector. Here is the solution - showing the na, nb and nk so we see the structures needed for multivariable use of ARX:
>> na = 2*ones(3,3)
na =
2 2 2
2 2 2
2 2 2
>> nb = 2*ones(3,5)
nb =
2 2 2 2 2
2 2 2 2 2
2 2 2 2 2
>> nk = ones(3,5)
nk =
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
>> sys_arx=arx(data_d,[na nb nk]);
>>
Note no error messages - fabulous!
Hi @Sean,
I apologize - my answer was incorrect. Thank you for posting the right solution from MATLAB support.
I misread the documentation. The official ARX reference https://www.mathworks.com/help/ident/ref/arx.html has two key statements that define the correct structure:
Under Input Arguments: "For a model with Ny outputs and Nu inputs: na is the order of polynomial A(q), specified as an Ny-by-Ny matrix of nonnegative integers."
Under Multiple-Input, Multiple-Output Models: "For multiple-input, multiple-output systems, na, nb, and nk contain one row for each output signal."
For your 3-output, 5-input system, this means:na must be 3×3 (not 3×1) - each output depends on all outputs' past values, nb must be 3×5 - each output depends on all inputs' past values, nk must be 3×5 - delay from each input to each output
The MATLAB support solution is exactly what the documentation specifies. Thanks for sharing it.
Fully understand - the documentation is "right"... but not easily readable. My deliberately non square MISO problem was good to tease out a simple explanation of the required structure. It would probably be a good example to include in the documentation.

Sign in to comment.

Products

Release

R2025b

Tags

Asked:

on 10 Feb 2026

Commented:

on 13 Feb 2026

Community Treasure Hunt

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

Start Hunting!