'DC Voltage Source' Block Parameter Name Error

5 views (last 30 days)
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'

Accepted Answer

Epsilon
Epsilon on 26 Jun 2025
Edited: Epsilon on 26 Jun 2025
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')

More Answers (0)

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!