What is the best way to execute a Simulink model step-by-step (interactively) from Matlab
조회 수: 19 (최근 30일)
이전 댓글 표시
Matlab provides at least 3 ways to execute a Simulink model step-by-step from Matlab. Which way is best? (See http://www.mathworks.com/support/tech-notes/1900/1903.html for background) Matlab technical support has not provided sufficient reposes or fixes for a clear best solution. If you have experience in this area, please provide input and source code if possible. My evaluation source code: http://www.et.byu.edu/~bjlarson/SystemModelTools/CompareSimulinkExecution.zip
The times of the following evaluation provide a comparison of executing 200 steps of identical Simulink models from matlab. At each step, new inputs are written from Matlab to the Simulink model and results are read.
- All-at-once model execution time for comparison. (Execution time 0.155641 seconds)
- "sim" step-by-step execution (Execution time 10.143009 seconds). Initialize each step with previous model state. Advantages: Can choose any solver from Simulink model. Can use standard Simulink In and Out ports. Output data can be at a higher resolution than evaluation steps. Disadvantages: very very slow.
- model(,,,'update') (Execution time 0.130168 seconds). Advantages: very fast. Even faster than all-at-once execution. Can use standard Simulink In and Out ports. Disadvantages: Need to create your own ODE solver. Output data is collected only at the model evaluation step resolution. Ignores all of the solver configuration parameters.
- set_param(,,'step') (Execution time 0.360453 seconds) Advantages: Can choose any solver from Simulink model. Output data can be at a higher resolution than evaluation steps. Moderately fast. Disadvantages: Must create S-function model input and model output ports. Cannot run Matlab headless.
Source files are located at http://www.et.byu.edu/~bjlarson/SystemModelTools/CompareSimulinkExecution.zip.
Running Evaluation:
"CompareSimulinkExecution.m" is the top-level evaluation script. "TestS.mdl" is the model used for the first 3 evaluation methods. "TestSParam.mdl" is used for "set_param(,,'step')" evaluation. "ModelInput.m" and "ModelOutput.m" are s-functions that force immediate data transfer to and from the Matlab workspace.
>> CompareSimulinkExecution
All-at-once sim call - provides a base model evaluation time:
Elapsed time is 0.115553 seconds.
Series of sim calls:
Elapsed time is 8.924163 seconds.
Step-by-step model calls:
Elapsed time is 0.124648 seconds.
set_param step:
Elapsed time is 0.463443 seconds.
>>
댓글 수: 6
Markus Buehren
2013년 6월 17일
I can't access the demo code at http://www.et.byu.edu/~bjlarson/SystemModelTools/CompareSimulinkExecution.zip ("you don't have permission..."). Is the code available anywhere else?
Jan
2018년 2월 16일
편집: Jan
2018년 2월 16일
Mojtaba Varmazyar wrote: "I have the same issue"
@Mojtaba Varmazyar: Please use flags only to inform admins and editors about contributions, which are not conform with the terms of use of the forum, e.g. due to rudeness or spam. Thanks.
The link from the original question is dead. Only the author could provide the files, but he is not active in the forum for 7 years now. This is the old problem of using links to externally stored files instead of attaching them directly in the forum.
답변 (5개)
Jarrod Rivituso
2011년 5월 12일
Forgive the basic question, but why can't you just set the simulation inputs to change at desired points in the simulation?
For instance, if my model had a root-level Inport block, and was set to Import the data [t,u] (in the Simulation -> Configuration Parameters -> Data Import/Export -> Input option), then I could do something like this:
>> t = [ 0; 2; 4; 6; 8]
>> u = [13;17;10;28;37]
Then my simulation would change the input at those times. Note, by default the Inport block will interpolate, but I could disable that by double-clicking the Inport block and disabling the Interpolate Data option.
댓글 수: 0
Brad
2011년 5월 12일
댓글 수: 6
Markus Buehren
2013년 6월 15일
I cannot access the example code zip file mentioned above ("You don't have permission ..."). Is there another location where to get it?
Markus Buehren
2013년 6월 15일
Hi,
when using method 3 (the model command), scopes in my discrete simulink model do not show any data. Also, the time (first parameter of the model function) does not seem to have any effect. I can set it to zero, to the step number or to [] without any influence.
Any ideas?
Yours Markus
댓글 수: 1
Kaustubha Govind
2013년 6월 17일
Markus: Could you please paste the exact sequence of commands that you're running?
Mojtaba Varmazyar
2018년 2월 16일
Hi,
I would like to access http://www.et.byu.edu/~bjlarson/SystemModelTools/CompareSimulinkExecution.zip. I wonder if anyone has access and send it to me.
Thanks Mojtaba
댓글 수: 0
참고 항목
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!