Tuning block parameters at each time step in Simscape Electrical
Show older comments
I am trying to find a way to change parameter values during a Simscape Electrical simulation using Matlab 2019B. I tested the method referenced below using a simple model of a battery and resistor, but the Resistor block does not seem to accept the updated parameter. Does the method below not work for Simscape Electrical blocks? Or is there a better way to do this?
StartFcn code:
set(0,'ShowHiddenHandles','on');
%Set up the arguments that will go into the gain block event callback listener
blk = 'var_resistor_test_24Jan2023/Resistor';
event = 'PostOutputs';
listener = @update_param_test;
%Create the listener
h = add_exec_event_listener(blk, event, listener);
Listener script:
function varargout = update_param_test(varargin)
%
%
%
% based on code available from Mathworks at:
%https://www.mathworks.com/matlabcentral/fileexchange/24935-tuning-block-parameters-at-every-time-step-in-a-simulation
temp=str2num(get_param('var_resistor_test_24Jan2023/Resistor','R')); % Get current Gain val
temp=temp + 1; % Increment
temp1=num2str(temp);
set_param('var_resistor_test_24Jan2023/Resistor','R',temp1);
1 Comment
Keith Int Veld
on 24 Jan 2023
Accepted Answer
More Answers (0)
Categories
Find more on Choose and Parameterize Blocks in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!