Is it possible to access simulink model workspace from TLC?

4 visualizaciones (últimos 30 días)
Tao Cui
Tao Cui el 21 de Mayo de 2023
Editada: Tao Cui el 17 de Jun. de 2023
I have a customized TLC for code generation that needs to store and access some customized parameter for code generation project. It is better to save and come together with the model in the model workspace.
I saw there is an example that TLC can access base workspace, it can be a workaround, but it is better to be with the model.
I tried the syntax in the post above, not working...
%assign b = FEVAL("evalin","model", xxxxx)
So, I also tried to write a function like below, it works in Matlab commandline
function type = getTypeFromModelWks(modelname,varname,portname)
wks = get_param(char(modelname),'ModelWorkspace');
var = wks.getVariable(char(varname));
type = eval(['var(''',char(portname),''');']);
But when I use it in TLC via FEVAL, I got syntax error, my value in model workspace is a string dictionary call codegen_Dict
%assign type = FEVAL("getTypeFromModelWks","%<CompiledModel.Name>","codegen_Dict", '%<id>')
So my question: is there a way to do it even? and how?

Respuesta aceptada

Tao Cui
Tao Cui el 17 de Jun. de 2023
Editada: Tao Cui el 17 de Jun. de 2023
I can answer my own question:
First, have a callback function in TLC, in my case it is a dialog
rtwoptions(oIdx).callback = 'callbackOptions(hDlg, hSrc)';
Then, in the callback function do this to save actual_var as Var_in_ModelWks in model workspace.
mdlWks = get_param(ModelName, 'ModelWorkspace');
assignin(mdlWks,'Var_in_ModelWks',actual_var);

Más respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by