Coder global structures with strings

4 次查看(过去 30 天)
Hello,
I am trying to port functional code that uses global structures with string elements in Matlab coder (code generation). I am unclear whether this is actually supported. Strings are, globals are, data structures are but combined ? In the end I am trying to generate a DLL that can be used by LabView.
A typical section of code is this:
function Output = CallMeFromLabView ( Mode)
global Data ; % this is a structure
Data.x =5;
Data.PathName = "/myfiles/subdir/here.dat"
if (mode == 1)
Data.PathName = "/trythesefolders/hello.txt"
end
return Output;
Ofcourse other functions will be called from here that use the global Data.
Coder returns with "unsupported global data initialization class for global variable Data ...." the first occurance of assigning the "PathName" string.
Is this even possible ? I know strings can be made variable length https://www.mathworks.com/help/coder/ug/define-string-scalar-inputs.html but it is unclear whether this works for globals. Does anyone have any example I could follow ?
Much appreciated
G

回答(1 个)

Adit Calambur
Adit Calambur 2021-9-2
Hi Gertjan,
If I understand you correctly, you are trying to generate deployable code for a project that has global structures with strings.
To generate code for MATLAB code that contains global variables, you must define and initialize global data in:
  • the MATLAB global workspace,
  • in a MATLAB Coder project,
  • or at the command line.
Global variables containing strings are supported. Global structure variables cannot contain handle objects or sparse arrays.
If you do not initialize global data in the project or at the command line, MATLAB Coder looks for the variable in the MATLAB global workspace. If the variable does not exist, MATLAB Coder generates an error.
For more information see Generate Code for Global Data.
~ Adit
  1 个评论
Gertjan Hofman
Gertjan Hofman 2021-9-2
Adit - thanks, but this isn't very clear- you just quoted a help page I had already read. I think what is required is definition of the structure outside of the function (say in the test calling code). But an example would really be helpful (if it exist, please point me to one).

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 MATLAB Coder 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by