Error copying a segment of values from an input vector to a property vector with different sizes using MatLab Coder
2 views (last 30 days)
While trying to generate a mex file, I'm getting the error "Dimension 1 is fixed on the left-hand side but varies on the right ([16 x 1] ~= [:? x 1]) " in the line code below
obj.prevInput = u(idx);
where obj.prevInput is a fixed length propertie (16x1), u is fixed length (128x1) input, and idx is a variable vector of index that address a continuous segement of u with size (16x1). Althought, all assigments to idx have the size of obj.prevInput, idx size is being identify as (1x:inf) by Matlab Coder.
How do I fix this error?
I have attached my full system object code.
Andy on 9 Apr 2020
Codegen is not smart enough to realize that a:a+c has fixed size (1xc). So:
If you want to make idx fixed size, try changing the line:
idx = initIdx : initIdx+int16(obj.smplPerSymb-1);
idx = initIdx + (0:int16(obj.smplPerSymb-1));
If you want to make the assignment to work with variable size idx you can do the following:
tmp = u(idx);
obj.PrevInput(:) = tmp(1:numel(obj.PrevInput))