Possibilities to change parameter in a simulation script used to calculate other paramters in the initialization file

Hi,
Is it possible to change a parameter in a simulation script where this parameter it’s used to calculate other parameters in the initialization file .m?
Example:
i would like to change the Vgrid=240 parameter,
but it’s is used to calculate
Vgrid_pk = 1.4142 * Vgrid; and others related parameters.

Many Thanks

Yes, you can change the constant values and any underlying calculations in the simulation script.

Hi, i have this script:

mdlVars = struct('Vgrid', 240);
simStruct = struct('ModelVars', mdlVars);
VgridValues = [180,200,240,276]; % in V
for ix = 1:length(VgridValues)
  simStruct.ModelVars.Vgrid = VgridValues(ix) ;
  out = plecs('simulate', simStruct);
end

in my m file initialization file

Vgrid_pk = Vgrid*1.4142;

And I use Vgrid_pk in the plecs simulation, but with the script my parameter Vgrid_pk don’t change with my Vgrid step parameter

You need to explicitly assign Vgrid_pk in your Simulation Script:

  simStruct.ModelVars.Vgrid_pk = VgridValues(ix)*sqrt(2) ;

See the execution sequence of a simulation script, taken from the PLECS Manual. The Model Initialization Commands execute first and then the values are overwritten by those assigned in the ModelVars structure. If you do not edit Vgrid_pk in your simulation script then the value from the Model Initialization Commands will persist.