You can perform this functionality with Parameter Sweeps. Double-click the Matlab component in the OptiSystem layout and choose “Add Parameter”. There you can name your variable and give some constraints on the values it can take. Creating this parameter will then create a variable in your Matlab workspace when the program is run, so you can use it in any of your calculations.
To perform multiple sweeps with different values for this parameter change the “Mode” from “Normal” to “Sweep”. In the value box, click on the small table icon. From there, you will be able to change the total number of sweeps and the values the variable takes.
Hope this helps!