Loading Structure from base workspace to embedded matlab

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.
Cheers !

2 件のコメント

Kaustubha Govind
Kaustubha Govind 2011 年 8 月 3 日
Have you tried making it a parameter of the Embedded MATLAB block?
Robbo
Robbo 2011 年 8 月 3 日
I have but I get an error message implying that it cannot accept a structure as an input, only constants/bus objects..etc if that makes any sense ?

サインインしてコメントする。

回答 (2 件)

Arnaud Miege
Arnaud Miege 2011 年 8 月 3 日

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)
%#codegen
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.
HTH,
Arnaud

6 件のコメント

Arnaud Miege
Arnaud Miege 2011 年 8 月 3 日
PS: Support for non-tunable MATLAB structure parameters in Embedded MATLAB Function blocks was introduced in R2008a and support for tunable MATLAB structure parameters in R2010a. See the release notes for more details:
http://www.mathworks.com/help/toolbox/simulink/rn/brh2esz-1.html#brj84ed-1
http://www.mathworks.com/help/toolbox/simulink/rn/bsawhtd.html#bsawlji
Robbo
Robbo 2011 年 8 月 3 日
Thanks Arnaud for the reply. I tried your example and it worked ! But when I tried it with my structure, which has 50 elements of which 3 are arrays, I get an error sayin
"MATLAB function interface error : Unable to map dialog parameter 1 of s-function 'sf_sfun' in mymodel/.../myblock/ SFunction to a run-time parameter. This parameter is an unsupported variable class such as a string, structure, cell or an unsupported data type"
Robbo
Robbo 2011 年 8 月 3 日
- mymodel and myblock are the names of my overall model and MATLAB function respectively
Arnaud Miege
Arnaud Miege 2011 年 8 月 3 日
Have a look at the restrictions when using structures:
http://www.mathworks.com/help/toolbox/eml/ug/bsvdbhz.html
It may be that your structure violates some of those restrictions.
Robbo
Robbo 2011 年 8 月 3 日
I see, as soon as I deleted the arrays in my structures it worked. Thank you
Gilles
Gilles 2013 年 3 月 5 日
It works like a charm !

サインインしてコメントする。

Fangjun Jiang
Fangjun Jiang 2011 年 8 月 3 日

1 投票

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.

1 件のコメント

Robbo
Robbo 2011 年 8 月 3 日
Oh I see, thank you very much. I was thinking of converting my structure into a bus object and tried the busCreate functionality which I assumed would turn a given MATLAB structure into a bus. I could then route this bus into the embedded matlab function as input, however I was unsuccessful again and obtained 2-3 error messages.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSimulink Coder についてさらに検索

質問済み:

2011 年 8 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by