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!