# Passing value from script to system parameters

**URL:** <https://forum.plexim.com/t/passing-value-from-script-to-system-parameters/1751>\
**Category:** PLECS\
**Tags:** plecs, c-script\
**Created:** [February 2, 2025, 8:16pm UTC](https://forum.plexim.com/t/passing-value-from-script-to-system-parameters/1751 "2025-02-02T20:16:47Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![MohamedMansour](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@MohamedMansour](https://forum.plexim.com/u/MohamedMansour)\
**Post date:** [February 2, 2025, 8:16pm UTC](https://forum.plexim.com/t/passing-value-from-script-to-system-parameters/1751/1 "2025-02-02T20:16:48Z")

</div>

I wrote a script where I update a certain parameter but I need to pass it to the initialization tab otherwise it gives me error where I should initialize it and of course this conflicts with written script for parameter sweeping.  
The script is shown below:

> values = linspace(0, 0.5, 5); % Sweep R from 1Ω to 10Ω in 5 steps  
> results = zeros(size(values));  
> for i = 1:length(values)  
> b = values(i); % Set parameter value  
> y = 1-b;  
> end

---

<div class="post-metadata">

**Author:** ![Bryan\_Lieblick](https://dub1.discourse-cdn.com/flex006/user_avatar/forum.plexim.com/bryan_lieblick/32/10_2.png) [@Bryan\_Lieblick](https://forum.plexim.com/u/Bryan_Lieblick)\
**Post date:** [February 3, 2025, 4:02pm UTC](https://forum.plexim.com/t/passing-value-from-script-to-system-parameters/1751/2 "2025-02-03T16:02:39Z")

</div>

Refer to the **Simulation Scripts** section of the PLECS Manual and the **Buck Converter with Parameter Sweep** demo model for an introduction to Simulation Scripts.

Note the use of a struct which contains the `ModelVars` field in the `plecs('simulate',opts)` command. Where `opts = {'ModelVars' : { 'b' : values(i), 'y' = 1-values(i) } }` (as an example). From the PLECS Manual:

> The optional field ModelVars is a struct variable that allows you to override variable values defined by the model initialization commands. Each field name is treated as a variable name; the field value is assigned to the corresponding variable. Values can be numerical scalars, vectors, matrices or 3d arrays or strings.
> 
> The override values are applied after the model initialization commands have been evaluated and before the component parameters are evaluated as shown in the figure below.
> 
> ![image](https://europe1.discourse-cdn.com/flex006/uploads/plecs/original/2X/b/b1f02a8813edb5d1911bbeeed663d441a39d2cd3.png)
