Error : Constant Operands

13 ビュー (過去 30 日間)
Life is Wonderful
Life is Wonderful 2022 年 3 月 23 日
編集済み: Life is Wonderful 2022 年 3 月 31 日
Hi
Iam implementing following code as show below
m = 10;
v = [1 1 2 : m]
v = 1×11
1 1 2 3 4 5 6 7 8 9 10
If I try to make fixed point , I am getting the error "Operands must be constants." I don't understand what is expected here. Can someone help me ?
Thank you
  2 件のコメント
Geoff Hayes
Geoff Hayes 2022 年 3 月 23 日
@Jogger - please clarify what you mean by "try to make this fixed point". What line of code leads to the error message?
Life is Wonderful
Life is Wonderful 2022 年 3 月 25 日
try to make this fixed point - Sorry I didn't write my requirment clearly.
I mean m is a Embedded.fi object here . Let say m = 10 , then class of m is 'double' but when I use numerictype or fi, then m is translated to 'embedded.fi'.
The problem i see colon operator doesn't seems to work for 'embedded.fi'.

サインインしてコメントする。

採用された回答

David Hill
David Hill 2022 年 3 月 25 日
Does changing to double work? I don't have the toolbox
v = [1 1 2 : double(m)]
  1 件のコメント
Life is Wonderful
Life is Wonderful 2022 年 3 月 28 日
Thanks a lot, it works

サインインしてコメントする。

その他の回答 (1 件)

Andy Bartlett
Andy Bartlett 2022 年 3 月 29 日
I'm puzzled by the error you described "Operands must be constants.".
When I attempt to reproduce the issue, I don't observe any problem.
I created this simple function.
function y = makeVec(m)
y = [1 1 2 : m];
end
When I test this with double or fixed-point inputs
u1 = 10;
u2 = fi(10);
y1 = makeVec(u1)
y2 = makeVec(u2)
the outputs are as expected.
y1 =
1 1 2 3 4 5 6 7 8 9 10
y2 =
1 1 2 3 4 5 6 7 8 9 10
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 0
Code generation can provide additional restrictions, so I tried that too.
codegen makeVec -args {u1} -o makeVec1_mex
codegen makeVec -args {u2} -o makeVec2_mex
y1m = makeVec1_mex(u1)
y2m = makeVec2_mex(u2)
Again, the outputs were as expected.
y1m =
1 1 2 3 4 5 6 7 8 9 10
y2m =
1 1 2 3 4 5 6 7 8 9 10
DataTypeMode: Fixed-point: binary point scaling
Signedness: Signed
WordLength: 16
FractionLength: 0
If you could clarify the original reproduction steps, that would be appreciated.
Andy
  1 件のコメント
Life is Wonderful
Life is Wonderful 2022 年 3 月 29 日
編集済み: Life is Wonderful 2022 年 3 月 31 日
The problem i see is coming from factorial function in matlab . Factorial function is unsupport by the fixed point designer . So I wrote my own implementation. I reliased the mistake in declaring fi Object and double togeather.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeFixed-Point Designer についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by