How to Make the Ports and Internal Variables of a FMU Block, Visible or Invisible?
5 ビュー (過去 30 日間)
古いコメントを表示
I am using Matlab 2023a to insert an FMU block into my Simulink model with the following two lines of code:
>> addpath('path/of/the/fmu/file')
>> fmu_block = add_block('simulink_extras/FMU Import/FMU', 'MyModel/MyFMU', 'FMUName', 'fmu_file.fmu');
The FMU block is successfully inserted into my model, and everything is currently working well. When I double-click on the FMU block, I can see options to enable or disable the visibility of each output port and internal variable:
Now, I'm wondering how I can use a Matlab script to control the visibility of output ports or variables. I've already attempted to retrieve port information using get_param(...), such as this:
port_name = get_param('Model/FMU/1', 'Name');
But unfortunately, Matlab gives me this error:
Invalid Simulink object name: 'Model/FMU/1'.
Caused by:
'FMU' is not a SubSystem block.
Therefore, the question remains: How can I retrieve or modify the visibility parameter of the ports and variables within an FMU block? I would appreciate any assistance anyone can provide.
0 件のコメント
回答 (1 件)
Anshuman
2024 年 7 月 18 日
The error you encountered can happen if the path is incorrect or if the block does not support the operation you're attempting.
In Simulink, the path to a block should be specified using the full hierarchical path from the model root. For example, if your FMU block is inside a subsystem, you need to include the subsystem name in the path.
You can try doing something like this to retrieve or modify the visibility parameter of the ports within an FMU block:
% Correct path to the FMU block
fmu_block_path = 'MyModel/MyFMU';
% Retrieve all parameters of the FMU block
fmu_params = get_param(fmu_block_path, 'ObjectParameters');
%This will display a list of all parameters associated with the FMU block. Look for parameters related to the visibility of ports and variables.
% Assuming 'OutputPortVisibility' is a parameter for controlling visibility
current_visibility = get_param(fmu_block_path, 'OutputPortVisibility');
disp(current_visibility);
Hope it helps!
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!