Defining Commands

You can define command-type actions to invoke desired functions within MATLAB. You can enter commands directly or load commands from a MATLAB M-Script file.

(If you have not already added an action, see Adding Actions.)

The MATLAB component automatically sets the current directory in the MATLAB session to the working directory for the component. If you want to set the current director to another directory, you need to provide an explicit cd command in your set of MATLAB commands. In addition, a variable called ESI_MATLAB_rundir is automatically set in the MATLAB session to allow you to refer to the working directory of the component, if necessary.

Do not define any commands that begin by deleting all the MATLAB variables from the current workspace, or you will lose all data sent to MATLAB by the component. In addition, the Java Socket interface is implemented by a Java object in the current workspace; if you delete all the MATLAB variables, you will lose this object and break the interface.

Important: Because the MATLAB component explicitly uses the cd command, any command or M-Script used in the MATLAB session must not define a variable with the name “cd” because this may override the command and would lead to errors.

  1. Double-click the MATLAB component icon .

    The MATLAB Component Editor appears.

  2. From the MATLAB Component Editor, click the Contents tab.

  3. Select the desired mapping-type action from the Initialize, Execution Order, or Finalize subtabs.

    An area for defining the Command appears on the right side of the editor.

    You can edit the name used to identify the Command action in the Command text box.

  4. Enter commands in the Enter MATLAB commands below or upload an M-Script file text area on the right side of the editor. You can enter the commands directly in the text area or load the commands from an existing MATLAB M-Script file.

    Important: You must check for syntactical errors in the given commands. Isight does not check for proper syntax before execution.

    1. Click Open, and locate the file that you want to load.
    2. Determine if you to store the M-Script in the model.

      Yes The current contents of the M-Script file are read and stored within the component (i.e., as if the contents had been typed into the text box). This command can be run no matter where the component executes. If you edit the M-Script file at a later time, you must also edit this command if you want it to run the updated script.
      No The MATLAB component creates an Isight input file parameter, configured to the absolute path and name of the M-Script file, and adds it to the component. When the command is run, the current contents of the M-Script file are returned by that file parameter. Therefore, this command can be run only if that path is accessible wherever the component is executed. If you edit the M-Script file at a later time, the component automatically runs the updated script.

    3. Click Open to load the file and to return to the MATLAB Component Editor.

  5. If desired, right-click in the Enter MATLAB commands below or upload an M-Script file text area, and click Scan for variables to map.

    The MATLAB editor scans the script currently displayed in the box for MATLAB variable names. The MATLAB variable names that appear in the script are used to create potential Isight parameters that can be mapped to or from the corresponding MATLAB variables.

    If you use this option, you may want to create all your commands before creating your mappings.

  6. Click OK to save your changes and to close the MATLAB Component Editor.