Array operations on simulink math function for maximum efficiency
조회 수: 2 (최근 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!