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 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.SLDVMatFile— MAT-file containing Simulink Design Verifier™
Example file types
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.
To contain your package folders, create a folder and add that folder path to the MATLAB® path.
To that folder, add the custom file that contains your signals, such as
In that folder, create a
+Simulinkfolder, and inside that folder, create a
Create a class that inherits from the
classdef MyFileType < Simulink.io.FileType
Save this class to
To register and interact with Signal Editor, implement these static methods:
Implement these public methods:
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.
Select the custom file that contains your custom signals.
Return to the class file and implement these additional public methods:
To import the custom signals, use the
dataOnFile = import(reader), where reader is the file type object for the reader, specified as a
Simulink.io.FileTypeobject. 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.Datais the cell array of signals and
dataOnFile.Namecontains the corresponding signal names.
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
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:
FileType Object for Use in Simulink
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.
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.
FileTypeobject for use in Simulink. This example creates a reader for signals with a custom format.
Create a class definition text file to define your
On the first line of the class definition file, specify the name of your
FileTypeand subclass from
Simulink.io.FileTypebase class enables you to use all the basic
For your class:
Add the appropriate basic
FileTypeobject methods to register and interact with Signal Editor.
Validate the signal formats.
Determine the contents of the signal file.
Load variables from the signal file.
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:
sltest.io.SimulinkTestSpreadsheet (Simulink Test) |