필터 지우기
필터 지우기

Loading Structure from base workspace to embedded matlab

조회 수: 4 (최근 30일)
Robbo
Robbo 2011년 8월 3일
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일
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
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일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 String에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by