Info
此问题已关闭。 请重新打开它进行编辑或回答。
Loop inside while iterator block - slow calculation
1 次查看(过去 30 天)
显示 更早的评论
I have somewhat large Simulink model which takes forever to run. I have located the problem inside a While iterator subsystem which is presented below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/156393/image.png)
In1 is a 1x1000 array and In3 is integer with value of 1000, ie the size of the array. Extract-function takes the n:th of this array and inserts it into the red circle where new array is generated based on the initial array and gained n:th value. The idea is to replace each value in the array with new, calculated value. In this example the value is only multiplied with 10, but in real model the calculation is more complex. The black circle generates values n=1,2,3...1000 which is used to select corresponding value in array. The blue circle makes sure that the While iterator subsystem is run until n=1000.
Used extract-function:
function i = extract(A,n)
i = A(n);
Used insert-function:
function A_out = insert(A_in,i,n)
A_in(n) = i;
A_out = A_in;
The outcome is what I want but it takes long time to compute. This example takes almost 5min to run (i7-5500U & 16GB). And this with 1x1000 array and 1 step. The real model would have up to 1500 time steps and a 1x9000 array changing each time.
I think that the loop (colored yellow) is the one to blame, but just can't come up with a solution to eliminate it. Is there some pre-made block or something that I can use to replace the red circle?
0 个评论
回答(0 个)
此问题已关闭。
另请参阅
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!