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

8 views (last 30 days)
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.

Accepted Answer

Sebastian Castro
Sebastian Castro on 22 Oct 2015
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 Comment
Andy
Andy on 22 Oct 2015
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Simulink Functions in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!