Error while using Simulink Programatic Interface for multiple inputs

3 次查看(过去 30 天)
While implementating the Programatic Interface I came across the issue of an error being thrown when the input size is larger than one.
For a one dimensional input, with the simulink model seen below. The file is saved as scratch.
[~, ~, ~, ~] = scratch([], [], [], 'sizes');
[sys, x0, blks, st] = scratch([], [], [], 'compile');
u = zeros(1, 1);
out = scratch([], u, 0.1, 'outputs')
This results in an output of:
out = 0
However when implementing two input ports seen below, an error is thrown.
[~, ~, ~, ~] = scratch([], [], [], 'sizes');
[sys, x0, blks, st] = scratch([], [], [], 'compile');
u = zeros(2, 1);
out = scratch([], u, 0.1, 'outputs')
The error states:
"Initial state vector "X0" must be a real vector of length 1"
What could the issue be?

采纳的回答

Raghvi
Raghvi 2023-3-15
It has come to my attention that the issue you are experiencing may be related to a problem with the documentation.
Instead of:
out = modelName(x,u,t,'outputs');
It should be
out = modelName(t, x, u,'outputs');
I have tried it with this command and it works.
The corresponding team is actively working towards resolving the issue and I appreciate your patience and understanding.

更多回答(1 个)

Raghvi
Raghvi 2023-3-13
Hey Fredrik,
To compute the output, the following line of code is used:
out = modelName(x,u,t,'outputs');
Where "x" are the state values, specified as a vector of real double values or as a structure.
You are using the command:
out = scratch([], u, 0.1, 'outputs')
Putting "x" as an empty vector. This is what seems to be causing the trouble. The initial state should not be empty. You might have received a warning while doing the same with a single input as well. If you explicitly define your initial state, the error goes away. Additionally, the time "t" must be real, double and scalar.
For additional information, you can refer to the following documentation:
  3 个评论
Raghvi
Raghvi 2023-3-13
Can you let me know what block parameters are you using so I can replicate the error at my end.
Raghvi
Raghvi 2023-3-13
I have found that since there are two inputs, you need to provide two initial states, for for each of them. Giving a 1x2 array as "x" resolved the issue for me.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Model Verification 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by