Main Content

importEnumTypes

Import enumerated type definitions to data dictionary

Description

importedTypes = importEnumTypes(dictionaryObj,targetTypes) imports to the data dictionary dictionaryObj the definitions of one or more enumerated types targetTypes. importEnumTypes does not import MATLAB variables created using enumerated types but instead, in support of those variables, imports the definitions of the types. The target data dictionary stores the definition of a successfully imported type as an entry. This syntax returns a list of the names of successfully imported types. importEnumTypes saves changes made to the target dictionary, so before you use importEnumTypes, confirm that unsaved changes are acceptable.

example

[importedTypes,importFailures] = importEnumTypes(dictionaryObj,targetTypes) additionally returns a list of any target types that were not successfully imported. You can inspect the list to determine the reason for each failure.

Examples

collapse all

Create a data dictionary myNewDictionary.sldd in your current working folder and a Simulink.data.Dictionary object representing the new data dictionary. Assign the object to the variable myDictionaryObj.

myDictionaryObj = Simulink.data.dictionary.create('myNewDictionary.sldd');

Run the script in the MATLAB file myDataEnum_ex_API.m. The file defines an enumerated type named InstrumentTypes using the Simulink.defineIntEnumType function and creates three variables based on the new type. Then, import the new variables from the base workspace to myDictionary_ex_API.sldd.

myDataEnum_ex_API
importFromBaseWorkspace(myDictionaryObj,'varList',...
{'firstEnumVariable','secondEnumVariable','thirdEnumVariable'});

Clear the imported variables from the base workspace. Before you can import an enumerated data type definition to the target data dictionary, you must clear the base workspace of any variables created using the target type.

clear firstEnumVariable
clear secondEnumVariable
clear thirdEnumVariable

Import the data type definition to myDictionary_ex_API.sldd.

importEnumTypes(myDictionaryObj,{'InstrumentTypes'})
ans = 

       className: 'InstrumentTypes'
    renamedFiles: {}

Input Arguments

collapse all

Target data dictionary, specified as a Simulink.data.Dictionary object. Before you use this function, represent the target dictionary with a Simulink.data.Dictionary object by using, for example, the Simulink.data.dictionary.create or Simulink.data.dictionary.open function.

Enumerated type definitions to import, specified as a cell array of character vectors or a string array. If any target types are defined using classdef blocks in MATLAB files or P-files, the files must be available on your MATLAB path so that importEnumTypes can disable them.

Example: {'myEnumType'}

Example: {'myFirstEnumType','mySecondEnumType','myThirdEnumType'}

Data Types: cell

Output Arguments

collapse all

Target enumerated type definitions successfully imported, returned as an array of structures. Each structure in the array represents one imported type. The className field of each structure identifies a type by name and the renamedFiles field identifies any renamed MATLAB files or P-files.

Enumerated type definitions targeted but not imported, returned as an array of structures. Each structure in the array represents one type not imported. The className field of each structure identifies a type by name and the reason field explains the failure.

Tips

  • Before you can import an enumerated data type definition to a data dictionary, you must clear the base workspace of any variables created using the target type.

  • You can define an enumerated type using a classdef block in a MATLAB file or a P-file. importEnumTypes imports type definitions directly from these files if you specify the names of the types to import using the input argument targetTypes and if the files defining the types are on your MATLAB path.

  • To avoid conflicting definitions for imported types, importEnumTypes renders MATLAB files or P-files ineffective by appending .save to their names. The .save extensions cause variables to rely on the definitions in the target data dictionary and not on the definitions in the files. You can remove the .save extensions to restore the files to their original state.

  • You can use importEnumTypes to import enumerated types defined using the Simulink.defineIntEnumType function. Because such types are not defined using MATLAB files or P-files, importEnumTypes does not rename any files.

  • Use the function Simulink.findVars to generate a list of the enumerated types that are used by a model. Then, use the list with importEnumTypes to import the definitions of the types to a data dictionary. See Enumerations in Data Dictionary for more information.

Version History

Introduced in R2015a