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

1 回表示 (過去 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))

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

製品


リリース

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by