Now that we have seen the core functions of a script we will run and check some more advanced scripts.
1. | Open 20-sim. |
2. | Open Octave (or Matlab). |
3. | In Octave/Matlab, change the local working directory to the tutorial folder inside your scripting working folder. E.g . type: |
cd 'C:\Users\yourusername\Documents\20simscripting\Octave\tutorials'
4. | In Octave/Matlab, execute the following script (e.g. type the command followed by ENTER): |
SetParameterAndRun
This script will open the model ControlledSystem.emx and run a simulation. Then a model parameter is changed and a second simulation run is performed. As explained in the previous topic, you can inspect the script in a text editor.
Compared to the basic script you will find a new function:
• | xxsimSetParameters: This function is used to set the parameter in the model with the new value. |
5. | In Octave/Matlab, execute the following script (e.g. type the command followed by ENTER): |
multipleRun
This script will open the model ControlledSystem.emx and run a simulation multiple times while changing a parameter. Then a model parameter is changed and a second simulation run is performed.
6. | In Octave/Matlab, execute the following script (e.g. type the command followed by ENTER): |
readAndSetParameters
This script will open the model ControlledSystem.emx and run a simulation. Then a model parameter is read from file and changed accordingly in the model, followed by a second simulation run.
You will find these new functions:
• | addpath: An additional path is given (../library/xxlib) to allow addtional (user defined) functions. |
• | xxlibReadCsv: This function is used to read a parameter name and value from a spreadsheet file. |
7. | In Octave/Matlab, execute the following script (e.g. type the command followed by ENTER): |
modelVerification
This script will open the model ControlledSystem.emx and run a simulation. After the run the simulation results are stored and plotted in Octave/Matlab. You will find these new functions:
• | xxsimSetLogVariables: Define which variables are going to be logged during the simulation run. |
• | xxsimGetLogVariables: Export the logged variables after the simulation run to Octave/Matlab. |
8. | In Octave/Matlab, change the local working directory to the tutorial folder. E.g. type: |
cd 'C:\Users\yourusername\Documents\20simscripting\examples'
here you can find more example scripts.