how to make simulink matlab function work

1 view (last 30 days)
prateek raj
prateek raj on 3 May 2013
Commented: Juan Herrera on 29 Jun 2016
i have matlab function m file like
function [out] = cdmacodegenerator(in)
out=ones(in,in)
end
it is working fine but when i try to use it in simulink via matlab function block
it gives error
  1. Data 'out' (#23) is inferred as a variable size matrix, while its specifiedtype is something else.
  2. MATLAB Function Interface Error: Data 'out' (#23) is inferred as a variable size matrix, while its specified type is something else.
  3. MATLAB Function Interface Error: Error in port widths or dimensions. Output port 1 of 'cdmacodegenerator/MATLAB Function1/in' is a one dimensional vector with 1 elements.

Answers (1)

Kaustubha Govind
Kaustubha Govind on 3 May 2013
In this case, the output signal of the block has varying dimensions (ie. size changes during execution of the model). Such signals are called Variable-Size signals in Simulink. Since Simulink does not support dynamic-memory allocation, such signals need to specify an upper-bound for their size. You might want to limit your input signal to a reasonable upper bound and configure your output signal as Variable-size and configure the same upper bound on the MATLAB Function block's Ports and Data Manager.
  1 Comment
Juan Herrera
Juan Herrera on 29 Jun 2016
Hi Kaustubha, I would like to be able to define the size via a calibration, therefore in the example from the question I set "in" as a parameter rather than an input and the variable "in" is defined in the workspace, however even in that case it returns the same error. To my understanding within the context of the simulation that parameter is fixed and so should be the size of the matrix. Is there a way to do this? Thanks in advance.

Sign in to comment.

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!