Array operations on simulink math function for maximum efficiency
1 回表示 (過去 30 日間)
古いコメントを表示
Hello, I am developing a model on simulink. I use math fucntion blocks while developing the model. Repetitive processes such as creating arrays, transferring arrays between blocks are often dominated in the content of Math function blocks. I use a for loop when creating arrays and storing data in matrix content, but I noticed that the for loop blocks simulink blocks and slows down the simulation a lot. How can I use a function for the matrix structure in which recursive functions will occur? I'm open to all suggestions.. Waiting for your answers. Thanks.
Example code: what ı want to do ------ obtained f array (1,100)
m=10;
n=10;
k=1;
f=zeros(1,m*n);
for i=1:1:m*n
f(i)=x(k)+y(i)...;
if k==n
k=0;
end
k=1+k;
end
0 件のコメント
採用された回答
Fangjun Jiang
2023 年 1 月 27 日
Instead of using "For Iterator Subsystem" block and "Math Function" block, I would suggest using the "MATLAB Function" block.
You would write similar code like what you have in your post.
3 件のコメント
Fangjun Jiang
2023 年 1 月 27 日
編集済み: Fangjun Jiang
2023 年 1 月 27 日
Then it depends on the needed processing task and the implementation code. You can do.
- Copy the MATLAB Function block code to a separate .m file and utilize the Profile Your Code to Improve Performance
- Similarly, use the Simulink Profile to see if the MATLAB Function block is the bottle neck.
- Some loop operation might be able to be replaced with matrix operation. Ask separate questions regarding those operations.
Also, the MATLAB Function block will be executed at every simulation step of the Simulink simulation. If the whole for-loop inside the MATLAB Function block only needs to be run once per simulation (for example, at the beginning of the simulation), then the MATLAB Function block needs to be put in a different place (e.g. inside an 'Initialize Function' block).
その他の回答 (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!