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 typeSimulink.io.BaseWorkspace
— Base workspace file typeSimulink.io.MatFile
— MAT-file file typeSimulink.io.ModelWorkspace
— Model workspace file typeSimulink.io.MDF
— Measurement data format (MDF) file typeSimulink.io.PluggableNamespace
— Different name space file typesSimulink.io.SLDVMatFile
— MAT-file containing Simulink Design Verifier™sldvData
structureExample 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.
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
mySignals.mat
.In that folder, create a
+Simulink
folder, and inside that folder, create a+io
folder.Create a class that inherits from the
Simulink.io.FileType
.classdef MyFileType < Simulink.io.FileType
Save this class to
yourfolder/+Simulink/+io
.To register and interact with Signal Editor or Root Inport Mapper, implement these static methods:
Implement these public methods:
At run time, call
whosImpl
viawhos
when you run theSimulink.io.FileType
object.whos
has the same syntax aswhosImpl
.
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.
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:
At run-time, call
loadImpl
viaload
when you run theSimulink.io.FileType
object.load
has the same syntax asloadImpl
.
To import the custom signals, use the
import
method.dataOnFile = import(reader)
, where reader is the file type object for the reader, specified as aSimulink.io.FileType
object. The output, dataOnFile, is a structure with the fieldsstructure.Data
, which is a cell array of signals, andstructure.Name
, which is a cell array of the corresponding signal names. For example,dataOnFile.Data
is the cell array of signals anddataOnFile.Name
contains the corresponding signal names.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
Create a
FileType
object for use in Simulink. This example creates a reader for signals with a custom format.Create a class definition text file to define your
FileType
object.On the first line of the class definition file, specify the name of your
FileType
and subclass fromSimulink.io.FileType
. TheSimulink.io.FileType
base class enables you to use all the basicFileType
object methods.For your class:
Add the appropriate basic
FileType
object methods to register and interact with Signal Editor or Root Inport Mapper.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, at the MATLAB command line, type:
open('Simulink.io.MySignalMatFile')
See Also
Classes
Simulink.io.FileType
|Simulink.io.BaseWorkspace
|Simulink.io.MatFile
|Simulink.io.MDF
|Simulink.io.PluggableNamespace
|Simulink.io.SignalBuilderSpreadsheet
|Simulink.io.SLDVMatFile
|sltest.io.SimulinkTestSpreadsheet
(Simulink Test)
Functions
exportImpl
|getFileTypeDescription
|Simulink.io.FileType.isFileSupported
|loadImpl
|loadAVariableImpl
|validateFileNameImpl
|whosImpl