What is the best way to execute a Simulink model step-by-step (interactively) from Matlab
이전 댓글 표시
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
Andreas Goser
2011년 5월 12일
I like to follow-up on your comment "Matlab technical support has not provided sufficient reposes", if you can give me the Service Request number for that.
Brad
2011년 5월 12일
Andreas Goser
2011년 5월 13일
Doing this in "comments", as I can't contribute technically. But I have a process comment: Part of this Service Request was raising an enhancement request and you followed up on the status 7 months after your first inquiry. And as this was not processed yet, I understand that a good next step is asking the community. One note about enhancement requests is that they are prioritized by severity/impact and frequency. The bad news is that you are still the first customer asking for this capability.
Andreas Goser
2011년 5월 13일
the first" -> "the only
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?
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개)
Walter Roberson
2011년 5월 12일
0 개 추천
"Best" for what goal?
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.
Brad
2011년 5월 12일
0 개 추천
댓글 수: 6
Walter Roberson
2011년 5월 12일
Any method that cannot produce responses within the target accuracy should not be considered. Methods that are slow can have "hardware thrown at them" but faster hardware cannot correct for incorrect solutions.
Jarrod Rivituso
2011년 5월 12일
Hi Brad,
What is driving the larger simulation? The phrase for doing this thing that I hear often is "cosimulation", FYI.
Brad
2011년 5월 12일
Arnaud Miege
2011년 5월 13일
Then, I'd say the best thing to do is generate C code using Embbeded Coder. From your C++ code, you should then be able to call into the step function at each time step and pass the necessary inputs to the model.
Brad
2011년 5월 13일
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일
0 개 추천
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일
0 개 추천
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
카테고리
도움말 센터 및 File Exchange에서 Manual Performance Optimization에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!