Main Content

Contains data for external data source

Since R2022b


A object is a handle object that can contain data from an external data source.

When you load data from an external source, for example by using the loadVariablesFromExternalSource function, Simulink® passes a reference to a object to the custom file adapter that can read that external file format. The file adapter, derived from the class, loads the data into the workspace in the form of MATLAB® variables and data objects. The workspace object acts as a cache for Simulink and can run a MATLAB script, similar to a base workspace. Symbol resolution includes symbols in the workspace. See run.


Only Simulink can create and manage a object, but you can create another handle for the workspace object by assignment.

copyWks = dsWks
copyWks = 
DataSourceWorkspace with no properties

To test a custom file adapter without creating a data source workspace, use the object.

Object Functions

clearVariablesClear specified variables from data source workspace
clearAllVariablesClear variables from data source workspace
getVariableReturn value of variable in data source workspace
getVariablesReturn values of variables in data source workspace
hasVariablesCheck if variables exist in data source workspace
listVariablesList variables in data source workspace
runExecute the specified MATLAB script in data source workspace
setVariableSet variable in data source workspace
setVariablesSet variables in data source workspace


collapse all

Define a getData method for an XML file adapter to populate the data from an XML file into the data source workspace that Simulink passes to the method.

This getData method reads an XML file in the following format:


function diagnostic = getData(adapterObj,sourceWorkspace,previousChecksum,diagnostic)​
    % Each time getData is called on the same source, sourceWorkspace is the same as
    % the last time it was called. Clear it to make sure no old variables exist.
    dom = xmlread(adapterObj.source);
    tree = dom.getFirstChild;
    if tree.hasChildNodes
        item = tree.getFirstChild;
        while ~isempty(item)
            name = item.getNodeName.toCharArray';
            if isvarname(name)
                value = item.getTextContent;
            item = item.getNextSibling;

Version History

Introduced in R2022b