MATLAB Answers

How to have variable-sized output for Simulink MATLAB-function block?

16 views (last 30 days)
Arun
Arun on 22 Jul 2013
I have a MATLAB function-block in Simulink and I would like to have the output port of the block dynamically sized based on an input parameter. Eg:
function[y] = MATLABblock(u, s)
y = someCalc(u,s) %%Returns array of size s %%
Is this possible?

  0 Comments

Sign in to comment.

Accepted Answer

Kaustubha Govind
Kaustubha Govind on 22 Jul 2013
I think this should work as long as you can enforce a maximum size for y. Simulink currently does not support dynamic memory allocation, so you must specify a maximum-size for variable-size signals. Please see the section on Variable-Size Data in the documentation to ensure that your output is configured as variable-size.

  2 Comments

Arun
Arun on 23 Jul 2013
Hi! Thank you for your response. I have got it to work. However, is there a restriction on how many such ports in a block can be variable-sized? The reason is, I have 8 identical ports with identical Port Settings (variable size with an upper bound of 1024), but only one of them works.
Arun
Arun on 23 Jul 2013
Sorry about the above comment. It was a bug in my code. I have corrected that and now it's all good. Thank you very much for your help!

Sign in to comment.

More Answers (0)