フィルターのクリア

How to change Matlab System parameters inside a For Each Subsystem ?

8 ビュー (過去 30 日間)
giuliano d'alterio
giuliano d'alterio 2024 年 5 月 8 日
回答済み: Yatharth 2024 年 6 月 24 日 9:20
Hi everyone.
I have a Matlab system with some tunable properties which i change with the write Parameter Writer block. Now i want to put the matlab system inside a for each block and change the tunable properties based on the input of the for each, but i'm having problem with the write parameter. My understanding is that the write parameter block is not compatible with the for each block. Is there a workaround for this?
  2 件のコメント
Avni Agrawal
Avni Agrawal 2024 年 5 月 8 日
Hi, can you share the simulink file for better understanding?
giuliano d'alterio
giuliano d'alterio 2024 年 5 月 8 日
I've added a simpler example of what i'm trying to do. In this case i've used a saturation block instead of the Matlab system, the error is the same.

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

回答 (1 件)

Yatharth
Yatharth 2024 年 6 月 24 日 9:20
Hi,
You can use the "MATLAB Function block" instead of "Parameter Writer" within the "For Each" subsystem to update the tunable properties. This method provides more flexibility and allows you to directly manipulate the properties within the "For Each" loop.
You can follow these steps:
  1. Replace the "Parameter Writer" block with "MATLAB Function" block inside the "For Each" subsystem
  2. In the "MATLAB Function" block, write a function that updates the tunable properties based on the input.
function updateTunableProperties(input)
%#codegen
% Example of updating a tunable property
persistent tunableProperty;
if isempty(tunableProperty)
tunableProperty = 0; % Initialize if needed
end
tunableProperty = input; % Update the property based on the input
% Use the updated property in your system
% Example: y = someFunction(tunableProperty, otherInputs);
end
3. Ensure that the tunable properties are defined as persistent variables or properties within the MATLAB Function block.
Please refer to the following documentation link to know more about “MATLAB Function” block: https://www.mathworks.com/help/simulink/ug/what-is-a-matlab-function-block.html

カテゴリ

Help Center および File ExchangeEvent Functions についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by