MATLAB/Octave

  

The MATLAB/Octave integration allows for scripts in M-files to be used as solvers within an optiSLang workflow. Use the file selector to open an M-file and the content is displayed on the Integration tab. Unlike other integrations, you cannot directly edit the displayed content. After opening a file, optiSLang tries to find script-local variables using auto-detection and list them in the table of suggested assignments. For an accurate representation of the workspace, perform a test run using the multi action button below the assignment table. Predefined variables containing meta information are provided and can be accessed within an M-script.

The MATLAB/Octave working directory is

  • the project directory for the reference file when using the dialog

  • and the current design directory during calculations.

Execution Settings Tab
OptionDescription
MATLAB versionSets the MATLAB version to use. On Windows systems all available MATLAB versions found in the registry can be selected. On Linux, paths to MATLAB installations must be defined in the configuration file entry SC_MatlabDirectoryPath.
Write logfileWhen selected, MATLAB's command output is saved in each design directory to the output_log.txt file.
Save inputsWhen selected, stores a parametrized copy of the MATLAB script and a MAT file containing the parameter values in the design directory.
Save outputsWhen selected, stores a MAT file containing the results values in the design directory. This can be useful for later re-evaluation of a particular design.
Connect ModeWhen selected, the connect run mode is used. It uses connect servers to establish and maintain a connection to MATLAB.
Max start timeWhen Connect Mode is selected, sets the time in seconds to wait for MATLAB instances to start. For parallel computation, this is the time to wait for all MATLAB instances to start.
Close when finishedWhen selected and Connect Mode is selected, specifies whether this node's MATLAB instances close after its execution has finished.
Batch ModeWhen selected, starts a fresh instance for each design and exchanges data with the help of MAT files.
Startup optionsWhen Batch Mode is selected, provides a list of common start up options that you can enable.
Custom optionsWhen Batch Mode is selected, allows you to enter custom options as you would on a command line.
Distinct working directoryWhen selected, creates an extra directory in the design directories for calculations.
Run Options

This node has general Run Options. The number of supported options is individual for each node.

Requirements for MATLAB Scripts

The script must be valid for execution in MATLAB. All parameters in the file must be defined in the following way:

            if ( ~exist('m','var') )    m = 1;     end;
            if ( ~exist('k','var') )    k = 20;    end;
            if ( ~exist('D','var') )    D = 0.02;  end;
            if ( ~exist('Ekin','var') ) Ekin = 10; end;
        

This is essential for parametrization because optiSLang sets the variable values prior to each script run. Without the existence check, these values will be overwritten.

Reserved names

Variable names prefixed with OSL_ are reserved for internal use and must be avoided in user scripts.

Type Mapping
IconoptiSLangMATLAB
 Real scalarReal scalar
 Complex scalarComplex scalar
 Real vector of length nReal 1 x n array
 Complex vector of length nComplex 1 x n array
 Real matrix of size m x nReal m x n array
 Complex matrix of size m x nComplex m x n array
 1Real XY-Data of size 1 x n1Time series with time of size n x 1 and real data of size n x 1
 1Complex XY-Data of size 1 x n1Time series with time of size n x 1 and complex data of size n x 1
 1Real signal of size m x n1Time series with time of size n x 1 and real data of size n x m
 1Complex signal of size m x n1Time series with time of size n x 1 and complex data of size n x m
MATLAB Simulink

You can use Simulink models in within optiSLang by using the MATLAB integration node. To load the Simulink model *.slx, *.mdl files into a MATLAB workspace, use the following script:

            % test existing SLX file and load it for time signal
            szSLXFile='oscillatorSLX';
            if exist(szSLXFile)== 4
                sim(szSLXFile);
            else
                error('No valid Simulink file found!!: %s',szSLXFile);
            end

The returning variables can be assigned to the local MATLAB workspace and then be used by optiSLang's variable registration mechanism.

            time=simulation.Time;
            x_values = simulation.Data;

Another way to integrate MATLAB results into optiSLang projects is to extract MATLAB data into *.mat files and read them into optiSLang.

Simulink documentation provides further and more detailed information on linking Simulink with MATLAB.

Troubleshooting
  • Linux:

    The path to one or more MATLAB installations must be specified in the configuration options. The entry SC_MatlabDirectoryPath may contain multiple colon-separated paths, for example,

    /path/to/MATLAB/R2012b:/path/to/MATLAB/R2015b

  • Windows:

    If MATLAB cannot be found on your Windows system make sure it is properly installed and the COM interface is registered. To do this:

    1. Ensure you have administrator permissions.

    2. Open a terminal ( or CMD shell) as an administrator.

    3. Enter the MATLAB installation path, for example, C:\Program Files\MATLAB\R2012a"\bin\matlab.exe /regserver.

Standard Slots

Besides the common integration slots the MATLAB node has the following slots.

Slot NameSlot TypeData TypeDescription
InOut
MaxParallelx  Number of parallel runs.
Path x Path to a MATLAB ("*.m, *.M") file.
MaxParallel x Number of parallel runs.
Supported Versions

See the Supported Integration Versions table.