Function 'version' not supported for code generation (R2021a)

For various reasons, I want my generated code to know which version of MATLAB codegen generated the code, because coder prior to R2023a would take a matlab function:
function [ a, b ] = foo ( c, d )
and generate it to
void foo( TypeC c, TypeDd, TypeA* a, TypeB* b);
but after R2023a, it would generate the function as:
TypeA foo( TypeC c, TypeD d, TypeB& b);
So it became necessary, in order to call functions generated a particular version of Matlab, I needed to know which version of coder generated the library, so I wrote a simple function that I asked coder to generate for me:
function [ n ] = mversion()
v = extractBefore( version, ' ' );
a = str2double(extractBefore( v, '.' )) * 1e9; vb = extractAfter( v, '.');
b = str2double(extractBefore( vb, '.' )) * 1e6;
n = (a + b)/1e9;
end
This code generates into a C++ function perfectly fine in many versions of Matlab coder from R2021a through R2023a, except in a recent installation of Matlab R2021a (older version of Matlab necessary to match a customer's environment), I get the error
??? Function 'version' not supported for code generation
What would cause this to successfully generate in one installation of Matlab 2021a and not another?

4 件のコメント

Walter Roberson
Walter Roberson 2023 年 8 月 23 日
Can you use verLessThan ?
Ivans Chou
Ivans Chou 2023 年 8 月 23 日
編集済み: Ivans Chou 2023 年 8 月 23 日
So, I tried:
if coder.const( verLessThan( 'matlab', '9.14' ))
% old way ...
else
% after R2023a way ...
end
and I get
??? Function 'verLessThan' not supported for code generation.
Something specifically unhappy about my coder installation. Did I forget to configure something in coder after I installed the toolbox?
Ivans Chou
Ivans Chou 2023 年 8 月 23 日
Just as a sanity check, I ran the Coder Toolbox "Euclidean" example in my R2021a installation and it generated successfully, so it's installed correctly.
Walter Roberson
Walter Roberson 2023 年 8 月 23 日
By the way: R2020b introduced isMATLABReleaseOlderThan and matlabRelease . But it looks like code generation is not available for those either.

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

 採用された回答

Richard McCormack
Richard McCormack 2023 年 8 月 24 日

1 投票

Hi Ivans,
It looks like MATLAB Coder support for version was officially introduced in R2021b.
If you need to use version in R2021a, I recommend using the following:
myversion = coder.const(@feval, 'version');
This should work in R2021a as well as current releases.
Let me know if that works for you.
Best,
Richard

2 件のコメント

Ivans Chou
Ivans Chou 2023 年 8 月 24 日
Yes. Works in R2021a. I will check on later versions, I think this is the solution.
Richard McCormack
Richard McCormack 2023 年 8 月 24 日
Glad to hear it :)

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

その他の回答 (0 件)

カテゴリ

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

製品

リリース

R2021a

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by