Is there a way to pass tables as a parameter to a Simulink "Matlab Function" block?

조회 수: 10 (최근 30일)
Not sure how much the question needs leaboration. I Have a native Matlab function working, and now need to make a Simulink block out of it. I'm really strugglink with both how to define the type, and pass the actual table name. Thanks for your help.

채택된 답변

Sebastian Castro
Sebastian Castro 2015년 10월 22일
The MATLAB Function block operates by generating code from the MATLAB code inside it, so the syntax is somewhat restricted.
I just did a quick search of the MATLAB Language features supported for code generation, and tables, being a new data type, are not yet supported.
Your solutions would be:
  1. Refactor your code so it doesn't use tables
  2. Tell MATLAB to use the interpreter (and not code generation) to run your function. This will be acceptable only if you don't plan on running your model outside the MATLAB environment, i.e., you're won't be generating code from the whole model.
For the second option, you could
  • Call the whole function using an "Interpreted MATLAB Function" block, or
  • Put all the table-related code in a separate "helper" function and force this function to be run by the MATLAB interpreter by using coder.extrinsic.
- Sebastian
  댓글 수: 1
Andy
Andy 2015년 10월 22일
Thanks for the response. While the second answer sounds interesting, I do plan to make production code to run outside of Matlab, but might look into when I have time.
I ended up with a slightly clungy solution, but it works as the the table is not that huge. I turned the table into a structure with each row name being a unique field, and each field is used only once. As Matlab function blocks handle structure parameters, I can then find the fieldname{1} value in the code.

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

추가 답변 (0개)

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by