Menu

ApplicationDevelopmentExampleApplication

Volkmar Glauche

Toy Example Programming

All computations used in this toy example are already implemented in MATLAB. The emphasis of this tutorial is on design considerations that determine the structure of inputs and outputs in the batch system and how these decisions influence the way inputs and outputs can be entered and passed on between modules. The files for this example can be found in the examples folder.

Adding two Numbers

In the first examples, exactly two numbers are added together. The output consists of a single value, the sum of the two inputs.

cfg_example_add1

This module takes two input arguments, which are of any type, that can be added (i.e. has a 'plus' method). The inputs are described as two single cfg_entry items and are represented as two separate input prompts in the user interface. Note that in all configuration files the leafs of the configuration tree are specified first. The tree is built by assigning the child items to the .val or .values fields of their parent items. This way, the root node of a tree is specified last in the configuration file. It would be possible to create the root node first and to assign values to its .val(ues) fields, too, but this would result in very lengthy subscript expressions.

cfg_example_add2

Here, the inputs have to be entered as a 2-vector. There is only one input prompt, which requires a [1 2] - sized input. This example can be easily extended to sum over an vector of arbitrary length by replacing the "2" in the input's .num field by "Inf".

Testing the Examples

To test the examples, they need to be added to the configuration. In cfg_ui, use "Add Application" and add the configuration file. A new menu item will show up which is named "New: Add1" or "New: Add2". The file " batch_example_add1.m" contains a batch using "Add1" and "Pass Output to Workspace" to compute the sum and pass the output to a workspace variable.

Grouping Modules

Each configuration file added by "Add Application" is added to the top level of the menu bar. For a large number of applications with many modules this is not very convenient. Therefore, all modules on an application should be grouped within an cfg_repeat tree. This tree can have multiple levels to group modules within an application. It is a good idea to keep configuration of each cfg_exbranch in separate config files and to have a master file that assembles them into a tree. The master file of this example is called cfg_example_master.m and covers all of the modules described here.

Sum over Vectors of any Length

cfg_example_sum

Only a slight modification to cfg_example_add2 is needed to make the computation run over an vector of any length: the "num" field of the input vector has to be set to [1 Inf] instead of [1 2] to allow to enter vectors of arbitrary length.

cfg_example_cumsum1

Again there are only slight modifications to cfg_example_sum to produce a cumulative sum output. The input side is unchanged, the computation and output side has to change, because cumsum returns a vector output. Referencing out(1) would only yield the first number, while referencing out(:) does not work, because this would resolve the dependency to the empty matrix already before the module is run. The solution is to assign the vector to a field in the output structure. Note that it is not possible to reference inidividual items of the output vector, because the length of it is not known in advance.

cfg_example_cumsum2

The limitation on the detail of output referencing possible in cfg_example_cumsum1 can be overcome by either fixing the min and max number of inputs to the same value or by specifying the number of input elements in a cfg_repeat element. The disadvantage of this approach is of course that each input value has to be entered separately.

Integer Division of two Numbers

This example shows, how to return two output arguments in a struct with two fields.


Related

Wiki: ApplicationDevelopmentIntroduction
Wiki: Home
Wiki: space.menu

Monday.com Logo