Basic Script

Navigation:  Toolboxes > Scripting Toolbox > Scripting in Octave/Matlab >

Basic Script

Previous pageReturn to chapter overviewNext page

When the scripting files are properly installed in your scripting working folder, we can run some tutorial scripts. Tutorial scripts are a step by step demonstrations of usage of the scripting functionality in 20-sim. These scripts are found in the tutorials subfolder of the scripting working folder. We will start with a basic script that opens and runs a 20-sim model.

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'

 

Note: 20-sim should be open before running the script!

4.In Octave/Matlab, execute the following command (e.g. type the following case sensitive command followed by ENTER):

runSimulation

 

Note: Octave may give a cryptic "undefined near line x column 1" message, if you type the command as runsimulation instead of runSimulation!

5.Now Octave / Matlab will give a message and ask you to press ENTER to continue.

The model ControlledSystem.emx is loaded into 20-sim and simulated.

6.Again Octave/Matlab will give a message and ask you to press ENTER to continue.

runSimulationScript

 

Now the simulation and model will be unloaded.

Inspecting the script

To see how the script is made, you can inspect it with a text editor.

1.Open a file browser and go to the tutorials folder (e.g. C:\Users\yourusername\Documents\20simscripting\Octave\tutorials)
2.Open the file runSimulation.m with a text editor like Notepad.

Core Functions

The core functions of the runSimulation script are:

addpath: The script starts with the command addpath('../library/xxsim'); This will enable Octave / Matlab to use the 20-sim scripting functions that are stored in the library subfolder of your scripting working folder.
xxsimConnect: This command opens a connection to 20-sim.
xxSimOpenModel: This command opens a model in 20-sim by giving the filename including the full path.
xxsimProcessModel: This command will process the model.
xxsimRun: This command will run a simulation.
xxsimCloseModel: This command will remove the simulation model from 20-sim.

These functions are the basis of scripting in 20-sim and will be present in this order in most scripts. Therefore you can use the script runSimulation.m as a template for any new script that you create.