How do I modify variables in the model workspace from a Simulink block?

조회 수: 40 (최근 30일)
Jeeven Hugh
Jeeven Hugh 2016년 8월 3일
편집: Jeeven Hugh 2016년 8월 8일
My Simulink block diagram has many gains whose values are variables stored in the Model Workspace.
I need to modify these gains dynamically using blocks in Simulink i.e. when a triggered subsystem is run, many of these gains have to change to new values specified by some Simulink block. I want these values to persist even after I terminate the simulation.
If this is possible, what block can do this?
Thanks.

답변 (1개)

Swarooph
Swarooph 2016년 8월 3일
Jeeven,
You can manipulate model workspace variables using MATLAB commands on a Simulink.Workspace variable. Refer to the following documentation to see how to make that happen in your particular case:
As to WHERE you would put these commands, it depends on your scenario.
  1. Do these variables change only at the end of the simulation so that it can be used for the next time you start a simulation? Then you can put it in the StopFcn callback (Documentation here).
  2. If the variables change EVERY time step during the simulation, try putting it in a MATLAB function block since this would execute every time step (Documentation here).
  댓글 수: 2
Jeeven Hugh
Jeeven Hugh 2016년 8월 4일
Thanks. This works, kind off. I am receiving an error when I try to use the MATLAB Function block.
In the MATLAB Function block, I am trying to read data from a .coe file using the textscan function in Matlab. My code works when it is not in Simulink i.e. just from a normal .m file; however, Simulink gives the following error:
*Simulink does not have enough information to determine output sizes for this block. ...
Function 'textscan' is not supported for code generation. Consider adding coder.extrinsic('textscan') at the top of the function to bypass code generation.*
I want to be able to generate C code from this Simulink project, so if I use that line, I will not be able to generate C code from my Simulink project. Is there any good workaround?
Thanks.
Jeeven Hugh
Jeeven Hugh 2016년 8월 8일
편집: Jeeven Hugh 2016년 8월 8일
I saved my coefficients to a .mat file, and I am able to import them into Simulink; however, I still cannot change the variables in the Simulink ModelWorkspace.
How do I change the variables in the Simulink ModelWorkspace and still be able to generate C code from my Simulink block diagram?
I tried using the assignin method, but that does not support code generation.
Thanks.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Subsystems에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by