
'DC Voltage Source' Block Parameter Name Error
5 次查看(过去 30 天)
显示 更早的评论
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'
0 个评论
采纳的回答
Epsilon
2025-6-26
编辑:Epsilon
2025-6-26
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Electrical Sensors 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!