Main Content

Simulink.io.ModelWorkspace Class

Namespace: Simulink.io

Read data in format used by model workspace

Since R2021b

Description

Simulink.io.ModelWorkspace inherits from the Simulink.io.FileType base class. It reads data formatted in a format used by the model workspace. Use model workspace file types to move data to and from the model workspace to a function, an automated process, or a user interface. To import data from the model workspace, use this command.

classdef ModelWorkspace < Simulink.io.FileType

The Simulink.io.ModelWorkspace class is a handle class.

Class Attributes

Abstract
false
HandleCompatible
true

For information on class attributes, see Class Attributes.

Properties

expand all

Source for initializing the variables in the model workspace, specified as one of these character vectors:

  • 'Model File' — The variables are stored in the model file. When you save the model, you also save the variables.

  • 'MATLAB Code' — The variables are created by MATLAB® code that you write and store in the model file.

  • 'MAT-File' — The variables are stored in a MAT-file, which you can manage and manipulate separately from the model file.

  • 'MATLAB File' — The variables are created by MATLAB code in a script file, which you can manage and manipulate separately from the model file.

Attributes:

GetAccess
public
SetAccess
public

Data Types: char | string

Name of the external file that stores or creates variables, specified as a character vector. To enable this property, set DataSource to 'MAT-File' or 'MATLAB File'.

Attributes:

GetAccess
public
SetAccess
public

Data Types: char | string

MATLAB code for initializing variables, specified as a character vector. To enable this property, set DataSource to 'MATLAB Code'.

Attributes:

GetAccess
public
SetAccess
public

Data Types: char | string

Methods

expand all

Examples

collapse all

Set up myExample to use with the model workspace and perform basic operations.

Set up the model workspace for the myExample. Assign timeseries([1;3]) as the value of aSignal.

myExample;
        
 mWS = get_param('myExample','ModelWorkspace');
 assignin( mWS, 'aSignal', timeseries([1;3]));

Determine the contents of the MAT-file aFileType associated with the Simulink.io.ModelWorkspace object.

aFileType = Simulink.io.ModelWorkspace( 'myExample.slx' );

%whos on file
out = whos( aFileType )
out = 

  struct with fields:

    name: 'aSignal'
    type: 'Signal'

Load signal names from the aFileType of the myExample model workspace.

aFileType = Simulink.io.ModelWorkspace( 'myExample.slx' );
%load
out = load( aFileType )
out = 

  struct with fields:

    aSignal: [1×1 timeseries]
aFileType = Simulink.io.ModelWorkspace( 'myExample.slx' );
%import all
out = import( aFileType )

out = 

  struct with fields:

     Data: {[1×1 timeseries]}
    Names: {'aSignal'}
out = 

  struct with fields:

     Data: {[1×1 timeseries]}
    Names: {'aSignal'}

Import the specified variable aSignal from the model workspace.

aFileType = Simulink.io.ModelWorkspace( 'myExample.slx' );
var = importAVariable( aFileType, 'aSignal')
timeseries

  Common Properties:
            Name: 'unnamed'
            Time: [2x1 double]
        TimeInfo: [1x1 tsdata.timemetadata]
            Data: [2x1 double]
        DataInfo: [1x1 tsdata.datametadata]

  More properties, Methods

Write a structure of signals to a MAT-file.

ts = timeseries([11112;36532415]);
aFileType = Simulink.io.ModelWorkspace('minportsOnly_withOutputs.slx');
[didWrite, errMsg ] = export(...
                          aFileType,'minportsOnly_withOutputs.slx',...
                           {'ts'},{ts},false)
didWrite =

  logical

   1

errMsg =

  0×0 empty char array

Version History

Introduced in R2021b