Is it possible to access simulink model workspace from TLC?

4 views (last 30 days)
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?

Accepted Answer

Tao Cui
Tao Cui on 17 Jun 2023
Edited: Tao Cui on 17 Jun 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);

More Answers (0)

Categories

Find more on Simulink Coder in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!