How to access to Simscape parameter via m script.

13 ビュー (過去 30 日間)
Mana
Mana 2025 年 3 月 3 日
コメント済み: Mana 2025 年 3 月 6 日
I can create model via simulink and I can place simulink and simscape component onto the model. I can access to both simscape and simulink components and set their parameters manually.
But, I can set parameter only using m-file only to simulink component. When using m-file to set parameter of simscape component, the parameter is not found.
%% Clear Workspace & Initialize
clear; clc; close all;
%% Load Simscape Library (if not loaded)
if ~bdIsLoaded('simscape')
disp('Loading Simscape library...');
load_system('simscape');
end
%% Create & Open Simulink Model
model_name = 'DAB_Converter_Model';
if bdIsLoaded(model_name)
close_system(model_name, 0);
end
new_system(model_name);
open_system(model_name);
%% Component Integration
%%dc_source_block = 'simelectronics/Sources/DC Voltage Source'; << incorrect source address
dc_source_block = 'fl_lib/Electrical/Electrical Sources/DC Voltage Source';
add_block(dc_source_block, [model_name '/Input_Voltage'], 'Position', [50, 50, 100, 100]);
set_param(model_name'/Input_Voltage', 'Constant Voltage', 100);
Error: Unrecognized function or variable 'Input_Voltage'.
On the model, DC Voltage Source component and the name Input_Voltage are placed. But, it seems Input_Voltage name is not visible to Simulink. How can I make all simscape component visible to simulink via m-file. I can access to the simscape component manually without problem,but not via m-file.
  2 件のコメント
Mana
Mana 2025 年 3 月 3 日
set_param([model_name '/Input_Voltage'], 'v0', '100'); fix this problem.
Mana
Mana 2025 年 3 月 6 日
I was looking at the parameter name of the component which is 'Constant Voltage', but the parameter name can be found by clicking on the component and look at the parameter field. In this case, the Constant Voltage parameter name for the Input_Voltage component is v0.

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

採用された回答

Mana
Mana 2025 年 3 月 3 日
set_param([model_name '/Input_Voltage'], 'v0', '100');

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeElectrical Sensors についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by