S-Function Level 1 vs S-Function Level 2
조회 수: 29 (최근 30일)
이전 댓글 표시
I have a problem. I have modeled a dynamic system( 5 inputs and 10 outputs) using S-Function Level-1 and Level-2. Both models work very well. My question is: Why the model that uses S-Function Level-2 runs its simulation very slowly? With the level 1 model simulation is very fast.
댓글 수: 1
want2know
2013년 7월 15일
Dear Miguel,
I have read your post and I understand that you have successfully developed your system in S-function level 1.
Do you mind to spend a couples of minutes to read the following: please
I have been using S-function to do the following:
[a1, b1] = choose_cells(c, d);
where a1 and b1 are outputs, c and d are inputs. All the variables are having a single value, except d is an array with 6 values.
Referring to the image attached, we all know that in S-function block, the input dimension must be SAME as output dimension, else we will get error, in this case, the input dimension is 7 while the output dimension is 2, so I have to include the "Terminator" blocks in the diagram for it to work perfectly, otherwise, I will get an error.
My problem is, when the system gets bigger, the array d could contain hundreds of variables, using this method, it means I would have to add hundreds of "Terminator" blocks in order to get this work, this definitely does not sound practical.
Could you please suggest me a wise way to implement this?
Thanks in advance.
답변 (4개)
Kaustubha Govind
2012년 3월 22일
I don't have a definite answer, and it's difficult to say not having seen your code, but it could be because Level-2 S-functions have a lot more features than Level-1 S-functions, so there is probably a lot of heavy-lifting/back-end work done by them? Exactly how slow are we talking about? Can you provide a ratio?
Ben
2012년 3월 23일
Profile your code but ticking the 'profile' entry in the Simulink tools menu.
You will probably see that the Level-2 function has its state functions called several thousand times more often than the Level-1 one does (for example my Level-1 function has its output function called ~6000 times, the Level-2 output function is called ~450,000 times!). This is the source of the slow-down, but I don't know how to fix it, sorry. Trying to work that out myself now!
댓글 수: 0
Ben
2012년 3월 23일
Solved it for my particular simulation: I had direct feedthrough incorrectly enabled for an input port. This created an agebraic loop.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Simulink Functions에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!