www.gusucode.com > mbc 工具箱 matlab 源码程序 > mbc/@mbcmodel/@model/Export.m

    function M = Export( obj, format, varargin )
%EXPORT Export model from an mbcmodel.model.
%
%   EXPORTED_MODEL = EXPORT( MODEL ) exports the model as to MATLAB.
%
%   EXPORTED_MODEL = EXPORT( MODEL, FORMAT ) exports the model in the
%   specified format. FORMAT can be 'MATLAB' or 'Simulink'.
%
% See also mbcmodel.abstractresponse.Export

%   Copyright 2004-2011 The MathWorks, Inc.
%   Based on response.Export: Revision: 1.1.4.1 Date: 2005/09/03 07:51:10 .
%       .

error( obj.pAssertNotBeingEdited( 'Model cannot be exported while it is being edited.' ) );
error( obj.pAssertIsFitted() );

if nargin < 2
    format = 'MATLAB';
end

m = obj.Object;

switch lower( format )
    case 'matlab'
        M = xregstatsmodel( m, varname( m ), [], [] );
    case 'simulink'
        out = i_mv2sl( m );
        if nargout,
            M = out;
        end
    otherwise
        error(message('mbc:mbcmodel:model:InvalidArgument2'));
end

%--------------------------------------------------------------------------
function mdlName = i_mv2sl( m )
% We need to open a system to export the model to.

% Use a temporary file name
[~, mdlName] = fileparts( tempname );

% Check the name of the model and create a new system if it doesn't
% already exist
if ~exist( mdlName, 'file' ),
    new_system( mdlName );
end
open_system( mdlName );

% Export model to Simulink
DO_PEV = false;
mv2sl( m, DO_PEV, mdlName );