How to pass a string into a Matlab function block?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ursula Garcia
el 29 de Abr. de 2013
Comentada: Maharshi Patel
el 29 de Sept. de 2020
Hello all, I want to pass a string into a Matlab function block.
This string is a mask parameter that must not be evaluated (it's a name). I'll try to pass it via a structure like this:
function Out = GetDiagAvail_mf(structArg)
%#codegen
coder.extrinsic('disp');
Out = coder.nullcopy(uint8(0));
disp(['in EML code, varName = ',structArg.varName]);
Out = coder.ceval('MyFct',coder.opaque('const char *',structArg.varName));
structArg is built in mask Initialization Pane like this: structArg.varName = Param;
'Param' value could be: 'MyString'.
I want to have in generated code: MyFct(MyString);
But I have this error:
_Error c2_lib_DSM.c: 161 undeclared identifier `MyString'
Warning c2_lib_DSM.c: 161 possible usage of MyString before definition
Warning c2_lib_DSM.c: 318 static `void function(pointer to void,pointer to const incomplete struct mxArray_tag defined at C:\Program Files\MATLAB\R2011b\extern\include\matrix.h 299,pointer to const char,pointer to void) c2_c_sf_marshallIn' is not referenced
Warning c2_lib_DSM.c: 291 static `pointer to const incomplete struct mxArray_tag defined at C:\Program Files\MATLAB\R2011b\extern\include\matrix.h 299 function(pointer to void,pointer to void) c2_c_sf_marshallOut' is not referenced _
1 errors, 3 warnings
Please, can you help me?
I'm using Matlab 2011b.
Thanks in advance,
Ursula
0 comentarios
Respuesta aceptada
Ryan Livingston
el 14 de Mayo de 2013
Hi Ursula,
You should simply be able to pass a MATLAB string to coder.ceval:
Out = coder.ceval('MyFct', structArg.varName);
Note that it will not be null-terminated automatically so that is required if "MyFct" expects a null-terminated C string:
Out = coder.ceval('MyFct', [structArg.varName char(0)]);
1 comentario
Maharshi Patel
el 29 de Sept. de 2020
Also, to pass a string as an argument to MATLAB function, you will need to uncheck the Tunable option for 'structArg' in the Ports and Data Manager (via 'Edit Data' button in Editor tab)
Más respuestas (0)
Ver también
Categorías
Más información sobre MATLAB Coder en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!