Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Simulink.ModelWorkspace

Describe model workspace

Description

Instances of this class describe model workspaces. Simulink® software creates an instance of this class for each model that you open during a Simulink session. See Model Workspaces for more information.

Property Summary

Name

Access

Description

DataSource

RW

Specifies the source used to initialize this workspace. Valid values are

  • 'Model File'

  • 'MAT-File'

  • 'MATLAB Code'

  • 'MATLAB File'

FileName

RW

Specifies the name of the MAT-file used to initialize this workspace. Simulink software ignores this property if DataSource is neither 'MAT-File' nor 'MATLAB Code'.

MATLABCode

RW

A string specifying MATLAB code used to initialize this workspace. Simulink software ignores this property if DataSource is not 'MATLAB Code'.

Method Summary

Name

Description

assignin

Assign a value to a variable in the model's workspace.

clear

Clear the model's workspace.

evalin

Evaluate an expression in the model's workspace.

reload

Reload the model workspace from the workspace's data source.

save

Save the model's workspace to a specified MAT-file.

saveToSource

Save the workspace to the MAT-file that the workspace designates as its data source.

whos

List the variables in the model workspace.

getVariable

Get value of variable from workspace.

hasVariable

Determine if variable exists in workspace.

Methods

assignin

Purpose

Assign a value to a variable in the model's workspace.

Syntax

assignin('varname', varvalue)

Arguments

varname

Name of the variable to be assigned a value.

varvalue

Value to be assigned the variable.

Description

This method assigns the value specified by varvalue to the variable whose name is varname.

See also

evalin

clear

Purpose

Clear the model's workspace.

Syntax

clear

Description

This method empties the workspace of its variables.

evalin

Purpose

Evaluate an expression in the model's workspace.

Syntax

evalin('expression')

Arguments

expression

A MATLAB® expression to be evaluated.

Description

This method evaluates expression in the model workspace.

See also

assignin

getVariable

Purpose

Get value of variable from workspace.

Syntax

variableValue = getVariable(workspaceHandle,variableName)

Arguments

workspaceHandle

Handle to the workspace.

variableName

Name of the variable.

Description

This method gets the value of a variable from a workspace.

hasVariable

Purpose

Determine if variable exists in workspace.

Syntax

variableExists = hasVariable(workspaceHandle,variableName)

Arguments

workspaceHandle

Handle to the workspace.

variableName

Name of the variable.

Description

This method determines whether a variable exists in a workspace.

reload

Purpose

Reload the model workspace from the workspace's data source.

Syntax

reload

Description

This method reloads the model workspace from the data source specified by its DataSource parameter. The data source must be 'MAT-File', 'MATLAB Code', or 'MATLAB File' .

See also

saveToSource

save

Purpose

Save the model's workspace to a specified MAT-file.

Syntax

save('filename')

Arguments

filename

Name of a MAT-file.

Description

This method saves the model's workspace to the MAT-file specified by filename.

    Note   This method allows you to save the workspace to a file other than the file specified by the workspace's FileName property. If you want to save the model workspace to the file specified by the file's FileName property, it is simpler to use the workspace's saveToSource method.

example

hws = get_param('mymodel','modelworkspace')  
hws.DataSource = 'MAT-File';  
hws.FileName = 'workspace';  
hws.assignin('roll', 30);  
hws.saveToSource;
hws.assignin('roll', 40);
hws.save('workspace_test.mat');

See also

reload, saveToSource

saveToSource

Purpose

Save the workspace to the MAT-file that it designates as its data source.

Syntax

saveToSource

Description

This method saves the model workspace designated by its FileName property.

example

hws = get_param('mymodel','modelworkspace')  
hws.DataSource = 'MAT-File';  
hws.FileName = 'params';  
hws.assignin('roll', 30);  
hws.saveToSource;

See also

save, reload

whos

Purpose

List the variables in the model workspace.

Syntax

whos

Description

This method lists the variables in the model's workspace. The listing includes the size and class of the variables.

example

>> hws = get_param('mymodel','modelworkspace'); 
>> hws.assignin('k', 2);
>> hws.whos

  Name      Size                    Bytes  Class

  k         1x1                         8  double array
Was this topic helpful?