필터 지우기
필터 지우기

passing structure from matlab workspace to embedded matlab function block

조회 수: 5 (최근 30일)
hasan
hasan 2012년 5월 16일
댓글: Akshaya Srinivasan 2018년 7월 13일
Hi,
How can i pass a structure that is defined in matlab workspace to simulink embedded matlab function block. e.g :
Numbers.a=1;
Numbers.b=2;
These are defined in matlab ws. Then by using the input port in simulink, can i pass this to matlab emb function block in simulink, or any other way?
Thanks four your replies...
  댓글 수: 1
Kaustubha Govind
Kaustubha Govind 2012년 11월 19일
Kyle: I would recommend posting your answer under the Answers section instead of as a comment on the question. Thanks! :)

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

답변 (2개)

Kaustubha Govind
Kaustubha Govind 2012년 5월 16일
You will need to define a Simulink.Bus signal to import the structure into Simulink as a nonvirtual bus - see Importing Structures of MATLAB timeseries Objects for Bus Signals to a Root-Level Input Port. Also refer to Working with Structures and Bus Signals in the MATLAB Function block documentation.
  댓글 수: 3
Kaustubha Govind
Kaustubha Govind 2012년 5월 17일
The Simulink.Bus object is used to specify the datatype of the signal (you can configure this as the output type of the Inport block and the input type of the MATLAB Function blok). To actually import your data via the Inport block, please refer to the first link in my answer. You will need to create a structure of timeseries objects.
Akshaya Srinivasan
Akshaya Srinivasan 2018년 7월 13일
Hi Both links don't work anymore. I am trying to do the same thing.

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


Kyle Andringa
Kyle Andringa 2012년 11월 28일
Yes, this can be done. As you mentioned, go into the EditData (Ports and Data Manager) page of the embedded Matlab file. Define a variable and choose Input as the Scope. Then on the outside of the embedded Matlab file assign the input to a Constant block. Within the Constant block, assign the structure (Numbers). On the signal attributes of the constant block, you must assign the output to a Bus signal which matches the structure (Numbers). This process is compatible with Rapid Accelerator.
Alternatively, you could choose the Scope as Parameter instead of Input. In this case you just name the Parameter "Numbers". This method is not compatible with Rapid Accelerator.
In both cases, you can only go one layer deep within the structure at a time. However, you can dig deeper in multiple steps. Example:
It doesn't like: new_var = Numbers.A.a But you could do: A = Numbers.A; a = A.a;
I'm not sure the reasoning for all of these nuances, I just know these items from (painful) experience.
Good Luck.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by