Filter löschen
Filter löschen

Is it possible to access simulink model workspace from TLC?

6 Ansichten (letzte 30 Tage)
Tao Cui
Tao Cui am 21 Mai 2023
Bearbeitet: Tao Cui am 17 Jun. 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?

Akzeptierte Antwort

Tao Cui
Tao Cui am 17 Jun. 2023
Bearbeitet: Tao Cui am 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);

Weitere Antworten (0)

Kategorien

Mehr zu Simulink 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!

Translated by