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