Skip an iteration in a ForEach subsystem

4 ビュー (過去 30 日間)
Omar Ashraf
Omar Ashraf 2023 年 8 月 2 日
コメント済み: Omar Ashraf 2024 年 9 月 19 日
Hello Everyone,
I currently have a ForEach subsystem that contains a statechart which gets replicated on all the inputs statically without skipping an iteration.
At certain conditions I would like to skip certain ForLoop iterations (just like the continue statement) to decrease overall execution time and have better efficiency.
How can such an issue be resolved?
Thank You

回答 (1 件)

Kanishk
Kanishk 2024 年 9 月 17 日
Hi Omar,
You are looking to enhance the efficiency of a "For Each" subsystem in Simulink by selectively skipping certain iterations. To achieve this, a "MATLAB Function" block can be employed prior to the "For Each" subsystem to filter the inputs that need to be processed.
Below is a sample code for the "MATLAB Function" block, which filters row 1,3 and 4 from the input and forwards this filtered output to the "For Each" subsystem:
function y = fcn(u)
% Control Logic
% Process only for iterations 1, 3 and 4
keepIter = [1 3 4];
y = u(keepIter,:);
Please go through the official MATLAB documentation of “MATLAB function block” and “For Each” subsystem.
Hope this helps!
Thanks
  1 件のコメント
Omar Ashraf
Omar Ashraf 2024 年 9 月 19 日
Thanks, but I was strictly trying to figure out how to do it in simulink space without writing any code down and ended it conducting the continue behaviour in stateflow.
the target was to end up with a simulink/stateflow model in which code generation was invloved.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeDeployment, Integration, and Supported Hardware についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by