I have an issue that keeps reoccurring when working with Matlab Coder. The problem is that Matlab does not know the size of my variables as manifested by the (:? x :?) in the Error report. When I try to use the assert statement before the variable is evaluated with assert(size(y,1)==1) or any other assert statement the variable is still evaluated as (:? x :?). I can not/do not wish to specify all variables in the command line as this is variables in functions within functions within functions.
My solutions to these problems is rather ugly at the moment. When working with scalars I define them as scalars by doing y = y(1) before the position that created an error. When working with a vector I am forced to use a for-loop in the same manner. But this can not have been the intentional usage. Are there any solutions to my problem, that allows a similar work flow as I have?
Use coder.varsize to control variable sizing. For example, if you have
a variable-length row vector x, you can write
The second input is the shape, where "inf" is a proxy for "unknown upper
bound". If you know an upper bound, then you can use that that if you
want. The last argument is a logical array that indicates which
dimensions are variable. So [false,true] or [0,1] indicate that the
first dimension is fixed and the second varies.
For inputs to entry point functions, you can create proxies for inputs
with shapes like that. For example, if you have a function FOO that
accepts a variable x like that, you could write
The first argument to coder.typeof determines the class. It has more
meaning in situations where the first argument is a struct. In a case
like this, all we get from it is class and complexity (i.e. whether the
data is real or complex). The second and third arguments are as in
The coder user interface makes it possible to define input types by
pointing and clicking.