Error copying a segment of values from an input vector to a property vector with different sizes using MatLab Coder

조회 수: 2 (최근 30일)
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.

답변 (1개)

Andy
Andy 2020년 4월 9일
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);
to:
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))

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by