Loading Structure from base workspace to embedded matlab
4 次查看（过去 30 天）
Does anyone know how to load a structure from base workspace to embedded matlab ?
The structure itself is a combination of constants and sub-structures containing more constants and all I really want is all this information to be made available in the embedded matlab function scope.
Arnaud Miege 2011-8-3
You need to define the scope of the structure as a parameter, not an input (which is the default). Here's a simple example. In the base workspace, I have defined:
s = struct;
s.a = 1;
s.b = 2;
and then I have a MATLAB Function block (previously called Embedded MATLAB Function):
function y = fcn(u,s)
y = s.a * u + s.b;
and s is defined as a parameter in the Model Explorer and it works fine. See Working with Structures and Bus Signals in the documentation.
Fangjun Jiang 2011-8-3
From the documentation, "The Embedded MATLAB Function block accepts inputs of any type that Simulink supports, including fixed-point and enumerated types. For more information, see Data Types Supported by Simulink in the Simulink documentation."
Looking further, structure data is not supported by Simulink. I guess you have to flatten your structure data then.