- the MATLAB global workspace,
- in a MATLAB Coder project,
- or at the command line.
Coder global structures with strings
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Adit Calambur
am 2 Sep. 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
Siehe auch
Kategorien
Mehr zu MATLAB Coder finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!