Borrar filtros
Borrar filtros

Error while using Simulink Programatic Interface for multiple inputs

1 visualización (últimos 30 días)
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?

Respuesta aceptada

Raghvi
Raghvi el 15 de Mzo. de 2023
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.

Más respuestas (1)

Raghvi
Raghvi el 13 de Mzo. de 2023
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 comentarios
Raghvi
Raghvi el 13 de Mzo. de 2023
Can you let me know what block parameters are you using so I can replicate the error at my end.
Raghvi
Raghvi el 13 de Mzo. de 2023
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Simulink Functions en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by