Clear Filters
Clear Filters

Return structure from setExternalInputsFcn

3 views (last 30 days)
William Stokes
William Stokes on 15 Mar 2022
Commented: Alvaro on 18 Jan 2023
I am using simulink.compiler.setExternalInputsFcn to declare a callback function which returns a value to each input port at each timestep.
Something like
simin = similink.compiler.setExternalInputsFcn(simin, inputsFcn)
If the return value from this function is scalar, or an array this seems to work fine. However, I want to return a structure, which will be mapped to a bus in Simulink.
I create the bus type in my model data dictionary, and set it as the type for the input port. I declare the callback like so
function v = inputsFcn(id, t)
v = struct('a',1,'b',2,'c',3);
end
But trying to run this gives the following line in the error...
ExternalInputsFcn could not be enabled due to the following incompatibilities:
and further down...
Caused by:
Error using Simulink.Simulation.internal.DesktopSimHelper
The data type of root inport 1 is not of a supported type.
Is this not allowed???
  1 Comment
Alvaro
Alvaro on 18 Jan 2023
Could you elaborate as to why you are trying to pass a struct into your inport?
I couldn't get simulink.compiler.setExternalInputsFcn to take a struct either but I am getting this error
The dimensions, data type or complexity of the return value from the ExternalInputsFcn for port 1 are incorrect.
Perhaps converting the struct to an array would work for you?

Sign in to comment.

Answers (0)

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!