- the MATLAB global workspace,
- in a MATLAB Coder project,
- or at the command line.
Coder global structures with strings
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposte (1)
Adit Calambur
il 2 Set 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:
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.
~ Adit
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!