Main Content

Create Custom File Type for Import to Signal Editor

By default, Simulink® supports signals in the forms listed in Forms of Input Data. To import file types containing signals that are not of the supported format, create and register your own custom file type reader. Simulink supports custom file type readers written with Simulink.io.FileType.

Simulink provides these file types.

  • Simulink.io.SignalBuilderSpreadsheet — Signal Builder file type

  • Simulink.io.BaseWorkspace — Base workspace file type

  • Simulink.io.MatFile — MAT-file file type

  • Simulink.io.ModelWorkspace — Model workspace file type

  • Simulink.io.MDF — Measurement data format (MDF) file type

  • Simulink.io.PluggableNamespace — Different name space file types

  • Simulink.io.SLDVMatFile — MAT-file containing Simulink Design Verifier™ sldvData structure

  • Example file types

    • Simulink.io.MySignalMatFile

    • Simulink.io.CreateSignals

    • Simulink.io.MDF

  • Simulink Test™ provides the sltest.io.SimulinkTestSpreadsheet (Simulink Test) file type.

Creating a file reader requires you to be familiar with object-oriented programming. It is intended for an advanced audience.

  1. To contain your package folders, create a folder and add that folder path to the MATLAB® path.

  2. To that folder, add the custom file that contains your signals, such as mySignals.mat.

    In that folder, create a +Simulink folder, and inside that folder, create a +io folder.

  3. Create a class that inherits from the Simulink.io.FileType.

    classdef MyFileType < Simulink.io.FileType
  4. Save this class to yourfolder/+Simulink/+io.

  5. To register and interact with Signal Editor, implement these static methods:

  6. Implement these public methods:

    • validateFileNameImpl

    • whosImpl

      At run time, call whosImpl via whos when you run the Simulink.io.FileType object. whos has the same syntax as whosImpl.

  7. Check if your class is registered. In the Signal Editor tab, click Import, then in the Import dialog box window, click Browse.

    The custom file that contains your signals, such as custompath/mySignals.mat, appears in the file browser.

  8. Select the custom file that contains your custom signals.

  9. Return to the class file and implement these additional public methods:

    • loadAVariableImpl

    • loadImpl

      At run-time, call loadImpl via load when you run the Simulink.io.FileType object. load has the same syntax as loadImpl.

  10. To import the custom signals, use the import method.

    dataOnFile = import(reader), where reader is the file type object for the reader, specified as a Simulink.io.FileType object. The output, dataOnFile, is a structure with the fields structure.Data, which is a cell array of signals, and structure.Name, which is a cell array of the corresponding signal names. For example, dataOnFile.Data is the cell array of signals and dataOnFile.Name contains the corresponding signal names.

  11. Return to the Signal Editor, click Import and try to import again.

After you successfully import your custom signals, you can manipulate them in Signal Editor. When done, and if you have implemented the exportImpl method, you can export the results by calling the export method for your reader at run time. Alternatively, you can use the export dialog from Export Signals to Custom Registered File Types.

For example implementations, see:

Define New FileType Object for Use in Simulink

A FileType object is a component you can use to create readers for signals that exist in formats not currently supported in Simulink. Write the reader in MATLAB and in the Signal Editor tab, click Import to register the reader and import the custom format file.

Note

Before importing, check that all editors for the custom file type class file are closed. Editing the custom file type class file while trying to import it as a reader causes unexpected behavior.

Define FileType Object

  1. Create a FileType object for use in Simulink. This example creates a reader for signals with a custom format.

  2. Create a class definition text file to define your FileType object.

  3. On the first line of the class definition file, specify the name of your FileType and subclass from Simulink.io.FileType. The Simulink.io.FileType base class enables you to use all the basic FileType object methods.

  4. For your class:

    1. Add the appropriate basic FileType object methods to register and interact with Signal Editor.

    2. Validate the signal formats.

    3. Determine the contents of the signal file.

    4. Load variables from the signal file.

    5. Import the signals.

    See the reference pages for each method and the full class definition file below for the implementation of each of these methods. To see the full class definition for a custom signal reader, run: open('Simulink.io.MySignalMatFile').

See Also

Classes

Functions

Related Topics