Is it possible to access simulink model workspace from TLC?

6 次查看(过去 30 天)
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?

采纳的回答

Tao Cui
Tao Cui 2023-6-17
编辑:Tao Cui 2023-6-17
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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink Coder 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by