Unrecognized function or variable when calling a LinearModel from a Simulink Interpreted Function block

2 visualizaciones (últimos 30 días)
I have a Simulink block that previously called a "Scattered Interpolant" function with 3 inputs using a Interpreted Function block in 2021a. I have added that function to the "base" workspace with the assignin command from Matlab. But when I replaced the "Scattered Interpolant" with a "LinearModel" with 5 inputs (created with fitlm and also added to the "base" workspace memory), I now get the errors:
An error occurred while running the simulation and the simulation was terminated
Caused by:
  • Error due to multiple causes.
  • Unrecognized function or variable 'TB3_C'.
  • Error in 'flow [kg//s]' while evaluating expression.
I presume that fitlm models are available to Simulink? What else could I have done wrong?
  2 comentarios
Dave Hall
Dave Hall el 12 de Oct. de 2023
In the script that I call the Simulink model from, I load the LinearModel and then assign it to the 'base' workspace:
assignin('base','TB3_C',TB3_C);
I then call it from the Interpreted Function call using feval:
Ultimately, I'll pass the parameters for the function call, but for now, the constants [0,0,7,0,0,0] return the correct value with no error when I run feval from the workspace.

Iniciar sesión para comentar.

Respuestas (1)

Jon
Jon el 12 de Oct. de 2023
Editada: Jon el 12 de Oct. de 2023
When I make an example following the steps you provide it runs without errors. Please attach your script, and Simulink model.
If you create or load TB3_C using a script (rather than a function) then I think it will already be in the base workspace, so the assignin seems redundant.
By the way, you can also use TB3_C.predict([0,0,7,0,0,0]) inside of your interpreted MATLAB function block rather than feval
  6 comentarios
Jon
Jon el 13 de Oct. de 2023
I would start by looking in your Workspace browser (tab on desktop) checking whether TB3_C is even there. I don't think it will be, because the error message is telling you the variable doesn't exist. Then try to just load the .mat file (I'm assuming from what you said that TB3_C is supposed to be in a .mat file) that you think has TB3_C in it and see if it is in the workspace. You can also right click on the .mat file and choose show details to see what is in the file, maybe TB3_C isn't even in there. Otherwise, most likely you have a small typo, for example a lower case where it should be capitalized in an assignment statement so perhaps you have an object called Tb3_C or TB3_c
Dave Hall
Dave Hall el 13 de Oct. de 2023
Very strange, but I found the problem. The function call was under a subsystem with a load statement in the Initialization tab of the mask to call a previous, differently named .mat file with different functions. When I deleted that load statement, everything runs as it should. I verified that this is the case. I genuinely don't understand why this would be, though, but I'm out of the woods.

Iniciar sesión para comentar.

Categorías

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

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by