Main Content

Create Custom File Type for Import

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 or Root Inport Mapper, 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 for Signal Editor or Root Inport Mapper.

    • In the Signal Editor tab, click Import, then in the Import dialog box window, click Browse.

    • In the Root Inport Mapper toolstrip, click From Custom File, then in the Import dialog box window, click Browse.

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

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

  10. 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.

  11. 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.

  12. Return to the Signal Editor or Root Inport Mapper, and try to import again.

After you successfully import your custom signals, you can manipulate them in Signal Editor or Root Inport Mapper. 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:

  • CreateSignals M-file — Implementation of how to create signals.

    At the MATLAB command line, type open('Simulink.io.CreateSignals').

  • MySignalMatFile M-file — Implementation of how to register custom file types to import into Simulink.

    At the MATLAB command line, type open('Simulink.io.MySignalMatFile').

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, register the reader, and import the custom format file in the Signal Editor or Root Inport :Mapper:

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.

  • In the Signal Editor tab, click Import, then in the Import dialog box window, click Browse.

  • In the Root Inport Mapper toolstrip, click From Custom File, then in the Import dialog box window, click Browse.

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 or Root Inport Mapper.

    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, at the MATLAB command line, type:

    open('Simulink.io.MySignalMatFile')

See Also

Classes

Functions

Related Topics