Operate on coder.Constant types for global variables in Matlab Coder

Say I want 2 global variables as -globals input to a codegen in Matlab Coder. The first is is a coder.Constant, and the second depends on the first, eg:
g1 = coder.Constant(3);
g2 = g1+1;
codegen example -globals {'g1',g1,'g2',g2}
This will give the error message "Undefined operator '+' for input arguments of type 'coder.Constant'."
Is there any way to operate on coder.Constant variables?
I know there is a very simple work around for this example, but for my code it would be a lot neater to operate directly on g1.
Alternatively:
Is it possible to extract the value in g1 as a normal data type? Eg the following:
a = double(g1);
But this returns the error message: "Conversion to double from coder.Constant is not possible."

3 件のコメント

Ryan Livingston
Ryan Livingston 2019 年 5 月 9 日
Interesting idea. We've made an internal note to think about this. To your second question if you can extract the value
c = coder.Constant(1)
c =
coder.Constant
1
c.Value
ans =
1
Philip Bergander
Philip Bergander 2019 年 5 月 10 日
The .Value field solves my problem entirely! Thanks a lot, Ryan!
It would still be interesting with an answer to my first question though.
Ryan Livingston
Ryan Livingston 2019 年 5 月 10 日
Is the first question: Is there any way to operate on coder.Constant variables?
If so, then there's no direct way to operate on coder.Constant values apart from extracting the Value field. We've made a note to think about what operating on these would mean and if we could support something like that.

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

回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で MATLAB Coder についてさらに検索

製品

リリース

R2017b

質問済み:

2019 年 5 月 9 日

コメント済み:

2019 年 5 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by