'DC Voltage Source' Block Parameter Name Error

조회 수: 25 (최근 30일)
희문
희문 2025년 6월 26일
편집: Epsilon 2025년 6월 26일
I'm trying to run a simple script to place a Simscape block, but an error has occurred.
What is the parameter name for the DC Voltage Source block?
block direction :
Simscape - Foundation Library - Electrical - Electrical Sources - DC Voltage Source
---------- My script ----------
clc;
% Create a new Simulink model
modelName = 'mySimscapeModel';
open_system(new_system(modelName));
% Load the DC Voltage Source block
blockPath = 'fl_lib/Electrical/Electrical Sources/DC Voltage Source';
add_block(blockPath, [modelName, '/DC Voltage Source 1']);
% Optionally, set parameters for the DC Voltage Source
set_param([modelName, '/DC Voltage Source 1'], 'Constant voltage', '5'); % Set output voltage to 5V
---------- Error ----------
Error using BDC_FET_test (line 12)
DC Voltage Source block (mask) does not have a parameter named 'Constant voltage'

채택된 답변

Epsilon
Epsilon 2025년 6월 26일
편집: Epsilon 2025년 6월 26일
Hi 희문 ,
The error occurs because the used parameter name, 'Constant voltage', does not match the internal parameter name used by the Simscape DC Voltage Source block.
In Simscape blocks, the names shown in the block dialog may differ from the internal parameter names required for scripting. To find the correct internal parameter name, please use the following MATLAB command:
get_param([modelName, '/DC Voltage Source 1'], 'DialogParameters')
This command returns all internal parameter names for the block. For example, in my case, the internal parameter name for 'Constant voltage' was 'v0' (as shown in the attached image).
To set the parameter value programmatically, use the following command:
set_param([modelName, '/DC Voltage Source 1'], 'v0','5')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Electrical Sensors에 대해 자세히 알아보기

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by