Main Content

exportImpl

Class: Simulink.io.FileType
Package: Simulink.io

Export signals to file

Syntax

[didWrite,errMsg] = exportImpl(exportFileName,varNames,varValues,isAppend)

Description

[didWrite,errMsg] = exportImpl(exportFileName,varNames,varValues,isAppend) exports signals from Signal Editor using the specified variables and returns didWrite and errMsg and saves them to exportFileName.

Input Arguments

expand all

File name for exported signals, specified as a character array.

Data Types: char

Signal names, specified as a cell array of character vectors.

Data Types: cell

Signal values associated with the signals in varNames, specified as a cell array of signal variables of supported types. For more information on supported types, see Choose a Base Workspace and MAT-File Format.

Data Types: cell

Append or overwrite signal file, specified as true (1) or false (0).

Data Types: logical

Output Arguments

expand all

Whether the signals were successfully written to exportFileName, returned as true (1) or false (0).

Error message, indicating errors with the reporting process, returned as a character array.

Examples

expand all

Subclass FileType class and implement exportImpl method.

classdef MySignalMatFile < Simulink.io.FileType

Implement the static method exportImpl.

methods
        
        function [didWrite,errMsg] = exportImpl(obj,fileName,cellOfVarNames, ...
                cellOfVarValues,isAppend)
            didWrite = false;
            errMsg = '';
            
            saveStruct = struct;
            
            for k = 1: length (cellOfVarNames)
                saveStruct.(cellOfVarNames{k}) = cellOfVarValues{k};
            end
            
            try
                if isAppend
                    save(fileName,'-struct','saveStruct','-append');
                else
                    save(fileName,'-struct','saveStruct');
                end
                didWrite = true;
            catch ME
                
                % Optional, return errMsg or throw hard error.
                % Returning an error message allows your automated
                % processes to carry on while allowing you to report the
                % error at a later time.
                errMsg = ME.message;
            end
            
        end
    end
end
Introduced in R2020a