sim command not opening Simulink model but workspace shows output variable ans ?!

What I'm tryin to do is to run a Simulink file from Matlab script so that I don't have to open it seperately. My Simulink model takes values from Matlab's workspace. So what I indent to do is run the maltab which put the variable with values into workspace, then run (simulate) the simulink model from matlab script only.
I'm using sim command but it doesn't seem to work (not running the simulink model), but there's this ans variable that shows up in workapsace area that is of no use to me. I'ven't used any "To Workspace" block either.

 채택된 답변

Walter Roberson
Walter Roberson 2021년 9월 6일
The graphical part is interface. The computation part is what is triggered when you run sim() . Part of running a simulation might be to update inputs to a graphing block, but that does not mean that it is mandatory that the blocks appear on the screen.
Using Simulink Scopes and similar is not like using figure() and so on, in that using figure() always causes a window to pop up. Simulink Scopes record data, and will display it if you open the graphical interface -- but the graphical interface is not necessary for the model to run.
You can use commands such as get_param and related to get the state of blocks.
You can log signals.
Especially if you have configured Single Output, https://www.mathworks.com/help/simulink/gui/single-simulation-output.html then the output of sim() is a Simulink.SimulationOutput object that holds the result of the simulation, and with the way you are running, that is going to get stored in ans . You should assign the value to a variable and examine it to see what went on with your model.

댓글 수: 3

Thank you sir, I got your point have made a small change in my script that does solve my issue of getting the value from simulink model into workspace and using that.
What I did to open and simulate my model is first open the model by just writing the model name (w/o any prefix(command) and extension name). and then using out result to calculate further values in script.
Thanks & Regards
Suraj S. Danu
The better approach would be to use
open_system Motor_Modelling
Yes it is sir. Thanks a lot.

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

추가 답변 (1개)

Is it possible that you have created a variable or another function with the same name? Try the command
which sim
to see what MATLAB is calling when you execute.

댓글 수: 1

No Sir,
It says built-in. followed by it location in system. (C:\..\simulink\core\api\sim).
It seems sim function only simulate the open model but NOT open-and-simulate the model.
So what i did to open just call the model and then used the sim command to simulate the same.
Thanks & Regards
Suraj S. Danu

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

카테고리

도움말 센터File Exchange에서 Event Functions에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2021년 9월 6일

댓글:

2021년 9월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by