Is it possible to access simulink model workspace from TLC?

조회 수: 4 (최근 30일)
Tao Cui
Tao Cui 2023년 5월 21일
편집: Tao Cui 2023년 6월 17일
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