Coder global structures with strings

4 visualizaciones (últimos 30 días)
Gertjan Hofman
Gertjan Hofman el 1 de Sept. de 2021
Comentada: Gertjan Hofman el 2 de Sept. de 2021
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

Respuestas (1)

Adit Calambur
Adit Calambur el 2 de Sept. de 2021
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 comentario
Gertjan Hofman
Gertjan Hofman el 2 de Sept. de 2021
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).

Iniciar sesión para comentar.

Categorías

Más información sobre MATLAB Coder en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by