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?
0 个评论
采纳的回答
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
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:
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Model Verification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!