importModel

Import model information from MATLAB tables

Syntax

archModel = systemcomposer.importModel(modelName,components,ports,connections,portInterfaces,requirementLinks)
archModel = systemcomposer.importModel(importStruct)
[archModel,idMappingTable,importLog,errorLog] = systemcomposer.importModel(___)

Description

archModel = systemcomposer.importModel(modelName,components,ports,connections,portInterfaces,requirementLinks) creates a new architecture model based on MATLAB® tables that specify components, ports, connections, port interfaces, and requirements.

archModel = systemcomposer.importModel(importStruct) creates a new architecture model based on a structure of MATLAB tables that specify components, ports, connections, port interfaces, and requirements.

[archModel,idMappingTable,importLog,errorLog] = systemcomposer.importModel(___) creates a new architecture model with output arguments idMappingTable with table information, importLog to display import information, and errorLog to display import error information.

Input Arguments

expand all

Name of model to be created, specified as a character vector.

Example: 'importedModel'

Data Types: char

Model component information, specified as a MATLAB table. The component table must include name, unique ID, parent component ID, and component type for each component. It can also include other relevant information such as referenced model, stereotype qualifier name, and so on, required to construct the architecture hierarchy.

Data Types: table

Model port information, specified as a MATLAB table. The ports table must include port name, direction, port ID, and component ID information. portInterfaces information may also be required to assign ports to components.

Data Types: table

Model connections information, specified as a MATLAB table. The requirement links table must include label, source ID, destination type, and destination ID information.

Data Types: table

Model port interfaces information, specified as a MATLAB table. The port interfaces table must include name, ID, parent ID, data type, dimensions, units, complexity, minimum, and maximum information.

Data Types: table

Model requirement links information, specified as a MATLAB table. The requirement links table must include label, source ID, destination type, destination ID, and type information.

Data Types: table

Model tables, specified as a structure containing tables components, ports, connections, portInterfaces, and requirementLinks.

Data Types: struct

Output Arguments

expand all

Handle to architecture model, specified as a systemcomposer.arch.Architecture object.

Mapping of custom IDs and internal UUIDs of elements, returned as a struct of MATLAB tables.

Data Types: struct

Confirmation that elements were imported, returned as a cell array of character vectors.

Data Types: char

Errors reported during import process, returned as an array of message MException objects. You can obtain the error text by calling the getString method on each MException object.

Examples

expand all

This example shows how to import and export architectures. In System Composer, an architecture is fully defined by three sets of information:

  • Component information

  • Port information

  • Connection information

You can import an architecture into System Composer when this information is defined in, or converted into, MATLAB tables.

In this example, the architecture information of a simple UAV system is defined in an Excel spreadsheet and is used to create a System Composer architecture model. It also links elements to the specified system level requirement. You can modify the files in this example to import architectures defined in external tools, when the data includes the required information. The example also shows how to export this architecture information from System Composer architecture model to an Excel spreadsheet.

Architecture Definition Data

You can characterize the architecture as a network of components and import by defining components, ports, connections, interfaces and requirement links in MATLAB tables. The component table must include name, unique ID, and parent component ID for each component. It can also include other relevant information required to construct the architecture hierarchy for referenced model, and stereotype qualifier names. The port table must include port name, direction, component, and port ID information. Port interface information may also be required to assign ports to components. The connection table includes information to connect ports. At a minimum, this table must include the connection ID, source port ID, and destination port ID.

The systemcomposer.importModel(importModelName) API :

  • Reads stereotype names from Component table and load the profiles

  • Creates components and attaches ports

  • Creates connections using the connection map

  • Sets interfaces on ports

  • Links elements to specified requirements

  • Saves referenced models

  • Saves the architecture model

Make sure the current directory is writable because this example will create files.

[stat, fa] = fileattrib(pwd);
if ~fa.UserWrite
    disp('This script must be run in a writable directory');
    return;
end
% Instantiate adapter class to read from Excel.
modelName = 'simpleUAVArchitecture';
% importModelFromExcel function reads the Excel file and creates the MATLAB
% tables.
importAdapter = ImportModelFromExcel('SmallUAVModel.xls','Components','Ports','Connections','PortInterfaces','RequirementLinks');
importAdapter.readTableFromExcel();

Import an Architecture

model = systemcomposer.importModel(modelName,importAdapter.Components,importAdapter.Ports,importAdapter.Connections,importAdapter.Interfaces,importAdapter.RequirementLinks);
% Auto-arrange blocks in the generated model
Simulink.BlockDiagram.arrangeSystem(modelName);

Export an Architecture

You can export an architecture to MATLAB tables and then convert to an external file

exportedSet = systemcomposer.exportModel(modelName);
% The output of the function is a structure that contains the component table, port table,
% connection table, the interface table, and the requirement links table.
% Save the above structure to excel file.
SaveToExcel('ExportedUAVModel',exportedSet);

Close Model

bdclose(modelName);
Introduced in R2019a