Automation Desk Accessing Mat Lab
Automation Desk Accessing Mat Lab
Accessing MATLAB
For AutomationDesk 2024‑A
If possible, always provide the serial number of the hardware, the relevant dSPACE License
ID, or the serial number of the CmContainer in your support request.
Important Notice
This publication contains proprietary information that is protected by copyright. All rights
are reserved. The publication may be printed for personal or internal use provided all the
proprietary markings are retained on all printed copies. In all other cases, the publication
must not be copied, photocopied, reproduced, translated, or reduced to any electronic
medium or machine-readable form, in whole or in part, without the prior written consent
of dSPACE GmbH.
This publication and the contents hereof are subject to change without notice.
Contents
Reference Information 27
Automation Blocks................................................................................................. 28
MATLAB............................................................................................................ 28
CloseMATLAB............................................................................................... 29
Execute......................................................................................................... 30
ExecuteMFile................................................................................................. 31
GetArrayFromMATLAB.................................................................................. 32
IsAlive........................................................................................................... 33
LoadMATFile................................................................................................. 34
MATLAB........................................................................................................ 35
OpenMATLAB............................................................................................... 36
PutArrayToMATLAB....................................................................................... 37
MATFile............................................................................................................. 38
CloseMATFile................................................................................................ 39
DeleteArrayFromMATFile............................................................................... 39
GetArrayFromMATFile................................................................................... 40
Information................................................................................................... 41
MATFile......................................................................................................... 42
OpenMATFile................................................................................................ 44
3
May 2024 AutomationDesk Accessing MATLAB
Contents
PutArrayAsGlobalToMATFile.......................................................................... 45
PutArrayToMATFile........................................................................................ 46
Automation 55
Basics on Automating the Access to MATLAB................................................ 55
Index 57
4
AutomationDesk Accessing MATLAB May 2024
About This Document
Content This document gives you information on how to access MATLAB via
AutomationDesk.
Symbol Description
Indicates a hazardous situation that, if not avoided,
V DANGER
will result in death or serious injury.
Indicates a hazardous situation that, if not avoided,
V WARNING could result in death or serious injury.
Indicates a hazardous situation that, if not avoided,
V CAUTION could result in minor or moderate injury.
Indicates a hazard that, if not avoided, could result in
NOTICE
property damage.
Indicates important information that you should take
Note
into account to avoid malfunctions.
Indicates tips that can make your work easier.
Tip
Indicates a link that refers to a definition in the
glossary, which you can find at the end of the
document unless stated otherwise.
5
May 2024 AutomationDesk Accessing MATLAB
About This Document
Symbol Description
Follows the document title in a link that refers to
another document.
Naming conventions dSPACE user documentation uses the following naming conventions:
Special Windows folders Windows‑based software products use the following special folders:
Accessing dSPACE Help and After you install and decrypt Windows‑based dSPACE software, the
PDF files documentation for the installed products is available in dSPACE Help and as PDF
files.
dSPACE Help (local) You can open your local installation of dSPACE Help:
§ On its home page via Windows Start Menu
§ On specific content using context-sensitive help via F1
PDF files You can access PDF files via the icon in dSPACE Help. The PDF
opens on the first page.
6
AutomationDesk Accessing MATLAB May 2024
Basics and Instructions
Introduction AutomationDesk provides the MATLAB Access library to access MATLAB® and
data stored in MAT files.
7
May 2024 AutomationDesk Accessing MATLAB
Basics and Instructions
Introduction To use the MATLAB Access library with its sublibraries, you have to know some
basics.
Sublibraries The MATLAB Access library consists of two sublibraries: MATLAB and MATFile.
MATLAB With the automation blocks of the MATLAB sublibrary, you can
create a MATLAB instance via AutomationDesk. The sublibrary provides a
MATLAB data object to create a MATLAB instance via AutomationDesk. The
automation blocks access this data object and can be used for data exchange
between MATLAB and AutomationDesk and for executing MATLAB commands
via AutomationDesk.
Note
MATFile With the MATFile sublibrary and its automation blocks, you can
access, read, write, and delete data to or from MAT files. The sublibrary provides
a MATFile data object to specify a MAT file. You can create a new MAT file,
read data from an existing MAT file, or modify an existing MAT file by using the
automation blocks. You do not need a MATLAB instance to work with MAT files.
Supported MATLAB versions To work with MATLAB via AutomationDesk, you need a correctly installed
MATLAB instance. AutomationDesk supports only MATLAB releases compatible
with the current dSPACE Release.
MATLAB data object To create a MATLAB instance, your AutomationDesk project must contain a
MATLAB data object. This object handles the MATLAB instance and can be
8
AutomationDesk Accessing MATLAB May 2024
MATLAB Access Basics
The MATLAB data object provides a data conversion setting for integer data
types. The default is no data type conversion.
MATFile data object To work with a MAT file, your AutomationDesk project must contain a MATFile
data object. The automation blocks of the MATFile sublibrary need a MATFile
data object. You have to specify the file name of the MAT file you want to work
with, the access mode, and the data conversion for integer data types. If you use
several MATFile data objects in your project, you must note AutomationDesk's
referencing mechanism. For further information, refer to Scope of Data Object
References (AutomationDesk Basic Practices ).
9
May 2024 AutomationDesk Accessing MATLAB
Basics and Instructions
Introduction The MATLAB Access library contains the two sublibraries MATLAB and MATFile.
MATLAB The MATLAB sublibrary provides functions to open and close MATLAB via
AutomationDesk, and to send data to it and retrieve data from it.
MATLAB The MATLAB data object creates the connection to MATLAB. With
the ConvertToDouble setting, you can specify how integer values are to be
converted when exchanged. For further information, refer to MATLAB on
page 35.
10
AutomationDesk Accessing MATLAB May 2024
Overview of the MATLAB Access Library Elements
Execute With the Execute automation block, you can execute MATLAB
commands via AutomationDesk. For further information, refer to Execute on
page 30.
LoadMATFile With the LoadMATFIle automation block, you can load a MAT
file into MATLAB's workspace via AutomationDesk. For further information, refer
to LoadMATFile on page 34.
IsAlive With the IsAlive automation block, you can check whether an access
to MATLAB is still possible. For further information, refer to IsAlive on page 33.
MATFile With the elements of the MATFile sublibrary, you can read data from and write
data to files in a MATLAB format.
MATFile The MATFile data object handles a MAT file. You can specify the
file name, the file access mode, and the ConvertToDouble settings, which you
can use to specify how integer values are to be converted when exchanged. For
further information, refer to MATFile on page 42.
Reference Information.............................................................................................................. 27
11
May 2024 AutomationDesk Accessing MATLAB
Basics and Instructions
Introduction When you use the blocks and data objects of the MATLAB Access library,
the data type conversion for AutomationDesk and MATLAB data types is
done automatically. For further data processing you need information on the
underlying conversion rules.
Conversion rules MATLAB basically works with array classes. If you want to exchange data
between MATLAB and AutomationDesk, these array classes must be mapped
to Python data types used in AutomationDesk. Data type conversion is required
for reading from a MAT file or the MATLAB workspace, and writing to a MAT file
or the MATLAB workspace.
Note
Data types The following table shows the conversion rules for the data types:
12
AutomationDesk Accessing MATLAB May 2024
Example of a MATLAB Access Sequence
Note
The data type mapping for the integer types additionally depends on the
Convert to double setting of the MATLAB and MATFile data object.
Array dimensions The following table shows the conversion rules according to the array
dimensions:
Example The following table shows some examples of data type mapping:
MATLAB AutomationDesk
1x1 int8 array Scalar of int, for example: 1
1x3 double array List of float, for example: [1.0, 2.0, 3.0]
3x1 int16 array List of lists of int, for example: [[1],[2],[3]]
2x3 int32 array List of lists of int, for example:[[1,2,3],[4,5,6]]
Introduction The following automation sequence shows you a simple program for access to
MATLAB and for reading and writing data. It automates only:
§ Opening MATLAB via AutomationDesk
§ Opening a MAT file via AutomationDesk
13
May 2024 AutomationDesk Accessing MATLAB
Basics and Instructions
The illustration below shows what the example sequence looks like:
Preconditions You have to specify some block-specific values in the Data Object Editor:
§ For the OpenMATFile and the LoadMATFile automation blocks, you have to
specify the name and location of the MAT file.
§ For the Execute automation block, you have to specify the MATLAB command
you want to execute, for example, plot.
Result When you execute the sequence, you open MATLAB and a MAT file. The MAT
file is loaded into MATLAB's workspace. A MATLAB command is executed and
the MAT file and MATLAB are then closed.
14
AutomationDesk Accessing MATLAB May 2024
How to Work with a MATLAB Instance
CloseMATFile............................................................................................................................ 39
CloseMATLAB........................................................................................................................... 29
Execute.................................................................................................................................... 30
LoadMATFile............................................................................................................................. 34
OpenMATFile............................................................................................................................ 44
OpenMATLAB........................................................................................................................... 36
Objective To work with MATLAB, your AutomationDesk project must contain a MATLAB
data object representing the MATLAB instance for the automated access.
MATLAB referencing The automation blocks of the MATLAB sublibrary need a MATLAB data object as
an input parameter:
§ If you have not specified a MATLAB configuration in the Project Manager, the
default configuration will be used.
§ If you have specified one MATLAB configuration in the Project Manager, this
data object is referenced automatically from the MATLAB automation blocks.
§ If you have specified more than one MATLAB configuration in the Project
Manager, the MATLAB automation blocks use the first configuration data
object of their hierarchy level or the explicitly referenced one. This behavior is
the same as for any other project‑specific data object. For further information,
refer to Scope of Data Object References (AutomationDesk Basic Practices ).
Preconditions § To work with MATLAB via AutomationDesk you need an installed MATLAB
on your PC. For further information on supported MATLAB versions, refer to
MATLAB Access Basics on page 8.
§ Make sure that MATLAB runs without errors and is configured according to
your needs before you open it as an instance of AutomationDesk.
§ You opened AutomationDesk and an AutomationDesk project with an empty
sequence beforehand.
15
May 2024 AutomationDesk Accessing MATLAB
Basics and Instructions
Result When you execute the sequence, you have opened and closed a MATLAB
instance via AutomationDesk.
Next step When you have configured your MATLAB instance, you should proceed with
How to Send Data to MATLAB on page 16.
References
CloseMATLAB........................................................................................................................... 29
MATLAB................................................................................................................................... 35
OpenMATLAB........................................................................................................................... 36
Objective If you want MATLAB to do some calculations for your AutomationDesk project,
you have to send data to it.
Data conversion AutomationDesk and MATLAB do not use the same data types. The data has
to be converted before being exchanged between them. When you use the
blocks of the MATLAB access library, conversion is done automatically. Data type
conversion is required for reading from a MAT file or the MATLAB workspace,
and writing to a MAT file or the MATLAB workspace. For further information,
refer to Conversion Rules for Exchanging Data Between AutomationDesk and
MATLAB on page 12.
The following instruction shows, as an example, sending data from a List data
object. In general, you can send every data type to MATLAB.
16
AutomationDesk Accessing MATLAB May 2024
How to Execute MATLAB Commands
Preconditions Before you can send data to MATLAB, you have to ensure that you have opened
MATLAB via AutomationDesk. Refer to How to Work with a MATLAB Instance on
page 15.
Result The data stored in the List data object is sent to MATLAB when you execute
the sequence. The block's MATLAB data object is automatically referencing the
MATLAB data object specified in the Project Manager.
Next step When you have sent data to MATLAB you should continue with How to Execute
MATLAB Commands on page 17.
References
PutArrayToMATLAB.................................................................................................................. 37
Objective You can execute MATLAB commands and MATLAB M files containing MATLAB
functions and scripts via AutomationDesk.
Preconditions Before you can execute MATLAB commands and M files via AutomationDesk,
you have to ensure that you have opened a MATLAB instance via
AutomationDesk. Refer to How to Work with a MATLAB Instance on page 15.
17
May 2024 AutomationDesk Accessing MATLAB
Basics and Instructions
Possible Methods AutomationDesk provides two different blocks for executing MATLAB
commands:
§ If you want to execute a single MATLAB command, you can use the Execute
automation block. The MATLAB command is stored in the automation block.
Refer to Method 1 on page 18.
§ If you want to execute an M file, you can use the ExecuteMFile automation
block. The executed file is not stored by AutomationDesk. Refer to Method 2
on page 18.
Result When you execute the sequence, the specified command or M file is sent via
AutomationDesk to MATLAB and then the command is executed by MATLAB.
Further steps When you have executed MATLAB commands via AutomationDesk, you should
proceed with How to Retrieve Data from MATLAB on page 19.
References
Execute.................................................................................................................................... 30
ExecuteMFile............................................................................................................................ 31
18
AutomationDesk Accessing MATLAB May 2024
How to Retrieve Data from MATLAB
Objective To get the results of the executed MATLAB commands or M files, you have to
receive data from MATLAB in AutomationDesk.
Data exchange between The data object used to store the data to be exchanged is a variant. It is mapped
AutomationDesk and automatically according to the conversion rules for data type mapping between
MATLAB AutomationDesk and MATLAB. For further information, refer to Conversion Rules
for Exchanging Data Between AutomationDesk and MATLAB on page 12.
You should also use the data type variant, if you create a data object in the
Project Manager to be used for data exchange. If you want to process the data in
your AutomationDesk sequence later on, you have to specify the right data type
as described in the data type mapping.
If you want to retrieve data from MATLAB or read it from a MAT file, ensure that
the specified array exists in MATLAB or the MAT file. Otherwise this will cause an
error.
Preconditions Before you can receive data from MATLAB, you have to ensure that:
§ For efficient MATLAB access it is recommended to have a MATLAB instance
opened before executing this automation block
§ MATLAB's workspace contains data which should be sent to AutomationDesk.
Result When you execute the sequence, the specified array is sent from MATLAB
to AutomationDesk. The received value is mapped automatically to the
corresponding Python data type.
Next Steps You can now proceed with processing the data in your AutomationDesk
sequence.
19
May 2024 AutomationDesk Accessing MATLAB
Basics and Instructions
GetArrayFromMATLAB.............................................................................................................. 32
Objective AutomationDesk lets you create, save, and load MAT files to and from MATLAB
to exchange data.
MATFile parameters Data exchange with MATLAB via MAT files is specified by:
§ Conversion of Python int data types to MATLAB float data types and vice
versa. For further information, refer to Conversion Rules for Exchanging Data
Between AutomationDesk and MATLAB on page 12.
MATFile referencing The automation blocks of the MATFile sublibrary need a MATFile data object as
an input parameter:
§ If you have not specified a MATFile data object in the Project Manager, the
default configuration will be used.
§ If you have specified a MATFile data object in the Project Manager before
creating the sequence, this data object is referenced automatically from the
MATLAB automation blocks.
§ If you have specified more than one MATFile data object in the Project
Manager, the MATFile automation blocks use the first configuration data
object of their hierarchy level or the explicitly referenced one. This behavior is
the same as for any other project‑specific data object. For further information,
refer to Scope of Data Object References (AutomationDesk Basic Practices ).
Access mode You can access your MAT file in different modes. You can select one of the
following access modes for the MATFile data object in AutomationDesk:
§ Access with write protection
§ Creating a new file or overwriting an existing file
20
AutomationDesk Accessing MATLAB May 2024
How to Work with MATFile Data Objects
For further information on the different modes, refer to MATFile on page 42.
Result When you execute the sequence, you open a MAT file, and can get information
about the MAT file and close it.
Note
If you want detailed information on the variables stored in the MAT file, you
can place the Information automation block in your sequence.
Next Steps When you can handle MATFile data objects, you should proceed with How to
Write Data to a MAT File on page 22.
21
May 2024 AutomationDesk Accessing MATLAB
Basics and Instructions
CloseMATFile............................................................................................................................ 39
GetArrayFromMATFile............................................................................................................... 40
Information.............................................................................................................................. 41
MATFile.................................................................................................................................... 42
OpenMATFile............................................................................................................................ 44
PutArrayToMATFile................................................................................................................... 46
Objective If you want to work with test results from AutomationDesk in MATLAB, you can
store these results in a MAT file permanently.
Possible methods AutomationDesk provides two different blocks for writing data to a MAT file:
§ If you want MATLAB to load the MAT file contents into its local workspace,
use the PutArrayToMATFile automation block.
§ If you want MATLAB to load the MAT file contents into its global workspace,
use the PutArrayAsGlobalToMATFile automation block.
Preconditions The following preconditions must be fulfilled to write data to a MAT file:
§ Before you can write data to a MAT file, you have to ensure that you have
created a MAT file data object in your AutomationDesk project. Refer to How
to Work with MATFile Data Objects on page 20.
§ In the access mode of the MATFile data object, you specified whether the data
to be written is appended to existing data or the data overwrites existing data.
Refer to MATFile on page 42.
§ If the access mode is u - Update, the specified MAT file must exist.
§ Ensure that you work with a sequence that contains an OpenMATFile and a
CloseMATFile automation block. You can use the sequence built in How to
Work with MATFile Data Objects on page 20 for this, for example.
22
AutomationDesk Accessing MATLAB May 2024
How to Read Data from a MAT File
Result When you execute the sequence, the specified data is written to the MAT file,
and when the MAT file is loaded, the data is stored in the local or global
workspace of MATLAB.
Next Steps When you have written data to a MAT file, you should continue with How to
Read Data from a MAT File on page 23.
CloseMATFile............................................................................................................................ 39
OpenMATFile............................................................................................................................ 44
PutArrayAsGlobalToMATFile...................................................................................................... 45
PutArrayToMATFile................................................................................................................... 46
Objective Before you can work with data from MAT files, the data must be extracted from
the MAT files.
Preconditions Before you can read data from MAT files, you have to ensure that:
§ You have created a MATFile data object in your AutomationDesk project.
§ The MAT file contains data to be sent to AutomationDesk.
§ The sequence contains an OpenMATFile and a CloseMATFile automation
block. The access mode to be specified can be one of the read-only access
modes.
Result When executing the sequence, AutomationDesk reads the specified data from
the MAT file.
23
May 2024 AutomationDesk Accessing MATLAB
Basics and Instructions
Next Steps If you have read data from MAT files, you should proceed with How to Delete
Data from a MAT File on page 24.
CloseMATFile............................................................................................................................ 39
GetArrayFromMATFile............................................................................................................... 40
MATFile.................................................................................................................................... 42
OpenMATFile............................................................................................................................ 44
Preconditions Before you can delete data from MAT files, you have to ensure that:
§ You have created a MATFile data object in your AutomationDesk project.
§ The MAT file contains data to be deleted via AutomationDesk.
Note
If you try to delete data from an empty MAT file, this will cause an error
when the sequence is executed.
Result When the sequence is executed, the specified data is deleted from the MAT file
via AutomationDesk.
24
AutomationDesk Accessing MATLAB May 2024
How to Delete Data from a MAT File
CloseMATFile............................................................................................................................ 39
DeleteArrayFromMATFile.......................................................................................................... 39
MATFile.................................................................................................................................... 42
OpenMATFile............................................................................................................................ 44
25
May 2024 AutomationDesk Accessing MATLAB
Basics and Instructions
26
AutomationDesk Accessing MATLAB May 2024
Reference Information
Reference Information
Automation Blocks.................................................................................. 28
27
May 2024 AutomationDesk Accessing MATLAB
Reference Information
Automation Blocks
Where to go from here Information in this section
MATLAB.................................................................................................. 28
AutomationDesk provides data objects and automation blocks to access
MATLAB data via MATLAB instance.
MATFile................................................................................................... 38
AutomationDesk provides data objects and automation blocks to access
MAT files.
MATLAB
Introduction AutomationDesk provides data objects and automation blocks to access MATLAB
data via MATLAB instance.
Data objects
MATLAB.................................................................................................. 35
To specify a MATLAB instance.
Automation blocks
OpenMATLAB.......................................................................................... 36
To open MATLAB.
CloseMATLAB.......................................................................................... 29
To close MATLAB.
IsAlive...................................................................................................... 33
To check whether a MATLAB instance is alive.
PutArrayToMATLAB................................................................................. 37
To put an array in the MATLAB workspace.
GetArrayFromMATLAB.................................................................. .......... 32
To get an array from the MATLAB workspace.
Execute................................................................................................... 30
To execute a MATLAB command.
ExecuteMFile........................................................................................... 31
To execute an M file.
28
AutomationDesk Accessing MATLAB May 2024
Automation Blocks
LoadMATFile............................................................................................ 34
To load a MAT file to the MATLAB workspace.
CloseMATLAB
Graphical representation
Purpose To close a MATLAB instance that was opened before in the current execution
thread.
Description The CloseMATLAB automation block is used to close a MATLAB instance that
was created beforehand in the current execution thread, i.e., in the executed
project, folder, or sequence.
Opened MATLAB instances are closed automatically at the end of the thread
execution. But if you want change from one MATLAB instance to another
within the same execution thread, it is useful to close the first MATLAB instance
explicitly using the CloseMATLAB block.
Note
§ With this block, you cannot close a MATLAB instance, that you
interactively created using the Open MATLAB command.
§ If MATLAB is not already running, this block opens MATLAB before
closing it.
Data objects This automation block provides the following data object:
29
May 2024 AutomationDesk Accessing MATLAB
Reference Information
References
Close MATLAB.......................................................................................................................... 48
MATLAB................................................................................................................................... 35
Open MATLAB.......................................................................................................................... 52
OpenMATLAB........................................................................................................................... 36
Execute
Graphical representation
Description The Execute automation block is used to send a MATLAB command to the
MATLAB instance. If it is a valid command, it is executed, otherwise an error
message is displayed in the Message Viewer.
Note
Tip
Data objects This automation block provides the following data objects:
30
AutomationDesk Accessing MATLAB May 2024
Automation Blocks
References
ExecuteMFile............................................................................................................................ 31
LoadMATFile............................................................................................................................. 34
MATLAB................................................................................................................................... 35
ExecuteMFile
Graphical representation
Description The ExecuteMFile automation block is used to execute MATLAB functions and
scripts saved to an M file.
Note
Data objects This automation block provides the following data objects:
31
May 2024 AutomationDesk Accessing MATLAB
Reference Information
References
Execute.................................................................................................................................... 30
MATLAB................................................................................................................................... 35
GetArrayFromMATLAB
Graphical representation
For further information on data type mapping, refer to Conversion Rules for
Exchanging Data Between AutomationDesk and MATLAB on page 12.
Note
32
AutomationDesk Accessing MATLAB May 2024
Automation Blocks
Data objects This automation block provides the following data objects:
References
MATLAB................................................................................................................................... 35
PutArrayToMATLAB.................................................................................................................. 37
IsAlive
Graphical representation
Description The IsAlive automation block is used to determine the status of the specified
MATLAB instance. It checks whether MATLAB reacts to an access from
AutomationDesk.
Note
33
May 2024 AutomationDesk Accessing MATLAB
Reference Information
Data objects This automation block provides the following data objects:
References
MATLAB................................................................................................................................... 35
LoadMATFile
Graphical representation
Description The LoadMATFile automation block is used to load the specified MAT file to the
MATLAB workspace. Its content is accessible via the workspace variables.
You can also use the Execute block to load a MAT file, but then it is more
complicated to specify dynamically the file to be loaded.
Note
34
AutomationDesk Accessing MATLAB May 2024
Automation Blocks
Data objects This automation block provides the following data objects:
References
MATFile.................................................................................................................................... 42
MATLAB................................................................................................................................... 35
MATLAB
Graphical representation
Description The MATLAB data object is used to handle the MATLAB instance that you work
with. If you have created a MATLAB data object in the Project Manager, this data
object represents a MATLAB instance that can be used by the automation blocks
of the MATLAB Access library. You can also open and close this MATLAB instance
interactively by using the Open MATLAB and Close MATLAB commands from
the data object's context menu.
Each automation block in the MATLAB folder of the MATLAB Access library must
reference a project-specific MATLAB data object in the Project Manager. If you
create the MATLAB data object in the Project Manager before you start building
your automation sequence, the automation blocks automatically reference the
MATLAB data object.
The MATLAB data object provides the Convert to double setting, which you
can set using the edit command. By default, no data type conversion for integer
types is done.
35
May 2024 AutomationDesk Accessing MATLAB
Reference Information
Note
You can only use one MATLAB instance at the same time.
If you created a second MATLAB data object, the blocks use the workspace
from the already opened MATLAB instance anyway.
References
Close MATLAB.......................................................................................................................... 48
Edit (MATLAB).......................................................................................................................... 51
Open MATLAB.......................................................................................................................... 52
OpenMATLAB
Graphical representation
Data objects This automation block provides the following data object:
36
AutomationDesk Accessing MATLAB May 2024
Automation Blocks
References
Close MATLAB.......................................................................................................................... 48
CloseMATLAB........................................................................................................................... 29
MATLAB................................................................................................................................... 35
PutArrayToMATLAB
Graphical representation
For further information on data type mapping, refer to Conversion Rules for
Exchanging Data Between AutomationDesk and MATLAB on page 12.
Note
Data objects This automation block provides the following data objects:
37
May 2024 AutomationDesk Accessing MATLAB
Reference Information
References
Edit (MATLAB).......................................................................................................................... 51
GetArrayFromMATLAB.............................................................................................................. 32
MATLAB................................................................................................................................... 35
MATFile
Introduction AutomationDesk provides data objects and automation blocks to access MAT
files.
Data objects
MATFile................................................................................................... 42
To specify a MAT file.
Automation blocks
OpenMATFile........................................................................................... 44
To open a MAT file.
CloseMATFile........................................................................................... 39
To close an opened MAT file.
Information............................................................................................. 41
To get information about the variables stored in a MAT file.
DeleteArrayFromMATFile......................................................................... 39
To delete an array from a MAT file.
PutArrayToMATFile.................................................................................. 46
To write an array to a MAT file.
PutArrayAsGlobalToMATFile..................................................................... 45
To write an array with global variables to the MAT file.
GetArrayFromMATFile................................................................... .......... 40
To get an array from a MAT file.
38
AutomationDesk Accessing MATLAB May 2024
Automation Blocks
CloseMATFile
Graphical representation
Description The CloseMATFile automation block is used to close a MAT file that you opened
before using the OpenMATFile automation block.
Whether the file is saved, and how, depends on the specified file access mode of
the referenced MATFile data object. For further information, refer to MATFile on
page 42.
Opened MAT files are closed automatically at the end of the thread execution.
But if you want change from one MAT file to another within the same execution
thread, it is useful to close the first MAT file explicitly using the CloseMATFile
block.
Data objects This automation block provides the following data object:
References
MATFile.................................................................................................................................... 42
OpenMATFile............................................................................................................................ 44
DeleteArrayFromMATFile
Graphical representation
39
May 2024 AutomationDesk Accessing MATLAB
Reference Information
Data objects This automation block provides the following data objects:
References
MATFile.................................................................................................................................... 42
GetArrayFromMATFile
Graphical representation
Description The GetArrayFromMATFile automation block is used to read the array, which
is specified by its name, from the MAT file. The Python representations of the
values are stored in the block's Array data object.
For further information on data type mapping, refer to Conversion Rules for
Exchanging Data Between AutomationDesk and MATLAB on page 12.
40
AutomationDesk Accessing MATLAB May 2024
Automation Blocks
Data objects This automation block provides the following data objects:
References
MATFile.................................................................................................................................... 42
PutArrayToMATFile................................................................................................................... 46
Information
Graphical representation
Description The Information automation block is used to get detailed information on the
variables stored in the specified MAT file. It corresponds to the whos command,
but additionally, the automation block provides separate data objects for the
names, sizes, bytes, and classes of the variables. If the MAT file is empty, a
message is displayed.
41
May 2024 AutomationDesk Accessing MATLAB
Reference Information
Data objects This automation block provides the following data objects:
References
MATFile.................................................................................................................................... 42
MATFile
Graphical representation
42
AutomationDesk Accessing MATLAB May 2024
Automation Blocks
Description The MATFile data object is used to create and configure a project-specific
MATFile data object in the Project Manager. This can be referenced by a block's
MATFile data object.
For both ways of specifying a MATFile data object, you can use its edit
command. Refer to Edit (MATFile) on page 49.
The MATFile data object provides the following settings which you can specify by
using its edit command.
FileName Lets you specify the path and name of the file you want to work
with. You can choose between an absolute or relative path to be used.
Absolute path Lets you specify the path as an absolute path in the project.
Relative path Lets you specify the path as a relative path in the project. It is
then a shortened path relating to the AutomationDesk project file. The path will
not be changed to a relative path if the project and the specified file are saved to
different drives.
Value Meaning
r Read
(default) The opened file can be read but not modified. The version of the MAT file is determined and will be
preserved.
u Update (read and write)
The file to be updated must exist. New input is appended to the existing content. The version of the MAT
file is determined and will be preserved.
w Write
If the file does not exist, it will be created. Existing contents are deleted. The HDF5‑based file format can
be read with MATLAB version 7.3 and later.
w4 Write Level 4 MAT file
If the file does not exist, a MAT file is created that can be read with MATLAB version 4 and earlier. Existing
contents are deleted.
wL Write character data using the default character set for your system
If the file does not exist, a MAT file is created that can be read with MATLAB version 6 or 6.5. Existing
contents are deleted.
43
May 2024 AutomationDesk Accessing MATLAB
Reference Information
Value Meaning
wz Write compressed data
If the file does not exist, a MAT file is created that can be read with MATLAB version 7 and later. Existing
contents are deleted.
Convert to double Lets you select the type conversion behavior. The
following values are provided:
Value Meaning
True If you use a PutArray block for integer Python types like int and long, the values are converted to the
double MATLAB type.
False (default) No data type conversion is done.
References
Edit (MATFile)........................................................................................................................... 49
OpenMATFile
Graphical representation
Description The OpenMATFile automation block is used to open the specified MAT file. The
file access behavior depends on the Mode and Convert to double settings.
When you add this block to your sequence, if you created a MATFile data
object in the Project Manager beforehand, the block's MATFile data object is
automatically referenced to the MATFile data object in the Project Manager.
The opened MATFile data object is accessible until the current thread, i.e.,
the executed project, folder, or sequence, terminates. Then the MAT file
is automatically closed. To close the MAT file beforehand, you can use a
CloseMATFile automation block.
44
AutomationDesk Accessing MATLAB May 2024
Automation Blocks
Data objects This automation block provides the following data object:
References
CloseMATFile............................................................................................................................ 39
MATFile.................................................................................................................................... 42
PutArrayAsGlobalToMATFile
Graphical representation
By setting the access mode of the MATFile data object, you can specify whether
the data to be written is appended to existing data or the data overwrites
existing data. Refer to MATFile on page 42.
For further information on data type mapping, refer to Conversion Rules for
Exchanging Data Between AutomationDesk and MATLAB on page 12.
Data objects This automation block provides the following data objects:
45
May 2024 AutomationDesk Accessing MATLAB
Reference Information
References
DeleteArrayFromMATFile.......................................................................................................... 39
GetArrayFromMATFile............................................................................................................... 40
MATFile.................................................................................................................................... 42
PutArrayToMATFile................................................................................................................... 46
PutArrayToMATFile
Graphical representation
Description The PutArrayToMATFile automation block is used to write data to the specified
MAT file.
By setting the access mode of the MATFile data object, you can specify whether
the data to be written is appended to existing data or the data overwrites
existing data. Refer to MATFile on page 42.
If the Convert to double setting of the MATFile data object is specified as TRUE,
values of integer Python types, like int and long, are converted to the double
MATLAB type.
For further information on data type mapping, refer to Conversion Rules for
Exchanging Data Between AutomationDesk and MATLAB on page 12.
Data objects This automation block provides the following data objects:
46
AutomationDesk Accessing MATLAB May 2024
Automation Blocks
References
DeleteArrayFromMATFile.......................................................................................................... 39
GetArrayFromMATFile............................................................................................................... 40
MATFile.................................................................................................................................... 42
PutArrayAsGlobalToMATFile...................................................................................................... 45
47
May 2024 AutomationDesk Accessing MATLAB
Reference Information
Close MATLAB......................................................................................... 48
To close an opened MATLAB instance interactively.
Edit (MATFile).......................................................................................... 49
To configure the MATFile data object.
Edit (MATLAB)......................................................................................... 51
To configure the MATLAB data object.
Open MATLAB......................................................................................... 52
To open MATLAB interactively.
Close MATLAB
Ribbon None
Context menu of MATLAB data object in the Project Manager,
Sequence Hierarchy Browser, and Data Object Editor
Shortcut key None
Icon None
Description With this command, you can close the MATLAB instance that you opened before
using the Open MATLAB command. A MATLAB instance that was opened by an
automation sequence cannot be closed by this command.
Note
48
AutomationDesk Accessing MATLAB May 2024
Commands And Dialogs
CloseMATLAB........................................................................................................................... 29
MATLAB................................................................................................................................... 35
Open MATLAB.......................................................................................................................... 52
Edit (MATFile)
Ribbon None
Context menu of MATFile data object in the Project Manager, Sequence
Hierarchy Browser, and Data Object Editor
Shortcut key None
Icon None
Others § Double-click MATFile data object
§ Press Enter with MATFile data object selected
Description With this command, you can configure the name and path of the MAT file,
the access mode, and the data type conversion for data exchange between
AutomationDesk (using Python data types) and MATLAB.
Dialog settings The edit command of the MATFile data object opens the MATFile Configuration
dialog.
File/Attachment These two options let you select whether to specify the file
via its name and path or via its name in the attachment folder.
File name You can use the Browse button to open a standard Open or Save
As dialog for specifying the MAT file you want to open or create. The dialog type
depends on the selected Mode parameter.
Absolute path Lets you specify the path as an absolute path in the project.
Relative path Lets you specify the path as a relative path in the project. It is
then a shortened path relating to the AutomationDesk project file. The path will
not be changed to a relative path if the project and the specified file are saved to
different drives.
49
May 2024 AutomationDesk Accessing MATLAB
Reference Information
File name Lets you specify the name of a file in the project's or custom
library's attachment folder. Files in custom libraries are specified in the following
format:
<CustomLibraryName>::<FileName>
Alternatively, you can select the file name from the list of files that are already
attached to the current project or to one of the open custom libraries.
Add Opens a file browser that lets you specify a file to be added to the
project's or library's attachment folder. The name of this file is automatically
selected in the File name input field.
Independent from the selected File/Attachment option, you can specify the
following:
Mode Lets you select the file access mode. The following values are provided:
Value Meaning
r Read
(default) The opened file can be read but not modified. The version of the MAT file is determined and will be
preserved.
u Update (read and write)
The file to be updated must exist. New input is appended to the existing content. The version of the MAT
file is determined and will be preserved.
w Write
If the file does not exist, it will be created. Existing contents are deleted. The HDF5‑based file format can
be read with MATLAB version 7.3 and later.
w4 Write Level 4 MAT file
If the file does not exist, a MAT file is created that can be read with MATLAB version 4 and earlier. Existing
contents are deleted.
wL Write character data using the default character set for your system
If the file does not exist, a MAT file is created that can be read with MATLAB version 6 or 6.5. Existing
contents are deleted.
wz Write compressed data
If the file does not exist, a MAT file is created that can be read with MATLAB version 7 and later. Existing
contents are deleted.
Convert to double Lets you select the type conversion behavior. The
following values are provided:
Value Meaning
True If you use a PutArray block for integer Python types like int and long, the values are converted to the
double MATLAB type.
False (default) No data type conversion is done.
50
AutomationDesk Accessing MATLAB May 2024
Commands And Dialogs
GetArrayFromMATFile............................................................................................................... 40
MATFile.................................................................................................................................... 42
PutArrayAsGlobalToMATFile...................................................................................................... 45
PutArrayToMATFile................................................................................................................... 46
Edit (MATLAB)
Ribbon None
Context menu of MATLAB data object in the Project Manager,
Sequence Hierarchy Browser, and Data Object Editor
Shortcut key None
Icon
Description With this command, you can configure the data type conversion for data
exchange between AutomationDesk (using Python data types) and MATLAB.
Dialog settings The edit command of the MATLAB data object opens the MATLAB Configuration
dialog.
Convert to double Lets you select the type conversion behavior. The
following values are provided:
Value Meaning
True If you use a PutArray block for integer Python types like int and long, the values are converted to the
double MATLAB type.
False (default) No data type conversion is done.
GetArrayFromMATLAB.............................................................................................................. 32
MATLAB................................................................................................................................... 35
PutArrayToMATLAB.................................................................................................................. 37
51
May 2024 AutomationDesk Accessing MATLAB
Reference Information
Access You can access the data objects of the MATLAB Access library via:
Purpose To insert data objects of the MATLAB Access library using the Home ribbon.
You can add data objects to your project in the Project Manager and to specific
automation blocks in the Sequence Builder, such as Exec automation blocks. The
data object is added to the selected element.
Automation Blocks................................................................................................................... 28
Open MATLAB
Ribbon None
Context menu of MATLAB data object in the Project Manager,
Sequence Hierarchy Browser, and Data Object Editor
Shortcut key None
Icon None
Description With this command, you can open the MATLAB instance that AutomationDesk
will start using the specified MATLAB data object. To save execution time, you
52
AutomationDesk Accessing MATLAB May 2024
Commands And Dialogs
can start MATLAB only once before executing several sequences that contain
automated access to MATLAB.
Note
§ Each MATLAB data object in the Project Manager uses the same MATLAB
instance. Only one MATLAB instance can be opened at the same time.
§ A MATLAB instance that you have opened interactively must also be
closed interactively using the Close MATLAB command.
Close MATLAB.......................................................................................................................... 48
MATLAB................................................................................................................................... 35
OpenMATLAB........................................................................................................................... 36
53
May 2024 AutomationDesk Accessing MATLAB
Reference Information
54
AutomationDesk Accessing MATLAB May 2024
Automation
Automation
Related information The AutomationDesk COM API provides the following objects for configuring the
access to MATLAB:
§ MATLAB (AutomationDesk Automation )
§ MATFile (AutomationDesk Automation )
55
May 2024 AutomationDesk Accessing MATLAB
Automation
56
AutomationDesk Accessing MATLAB May 2024
Index
Index
MATFile 42
C MATFile overview 38
MATLAB 35
Close MATLAB command 48
MATLAB overview 28
CloseMATFile
OpenMATFile 44
MATLAB Access 39
OpenMATLAB 36
CloseMATLAB
PutArrayAsGlobalToMATFile 45
MATLAB Access 29
PutArrayToMATFile 46
Common Program Data folder 6
PutArrayToMATLAB 37
MATLAB instance
D working with 15
DeleteArrayFromMATFile MATLAB library
MATLAB Access 39 example 13
Documents folder 6 MATLAB overview
MATLAB Access 28
E
O
Edit command (MATFile) 49
Edit command (MATLAB) 51 Open MATLAB command 52
Execute OpenMATFile
MATLAB Access 30 MATLAB Access 44
ExecuteMFile OpenMATLAB
MATLAB Access 31 MATLAB Access 36
G P
GetArrayFromMATFile PutArrayAsGlobalToMATFile
MATLAB Access 40 MATLAB Access 45
GetArrayFromMATLAB PutArrayToMATFile
MATLAB Access 32 MATLAB Access 46
PutArrayToMATLAB
MATLAB Access 37
I
Information
MATLAB Access 41
inserting AutomationDesk library elements
MATLAB Access 52
IsAlive
MATLAB Access 33
L
LoadMATFile
MATLAB Access 34
Local Program Data folder 6
M
MATFile
MATLAB Access 42
MATFile overview
MATLAB Access 38
MATLAB
MATLAB Access 35
MATLAB Access
CloseMATFile 39
CloseMATLAB 29
DeleteArrayFromMATFile 39
Execute 30
ExecuteMFile 31
GetArrayFromMATFile 40
GetArrayFromMATLAB 32
Information 41
IsAlive 33
LoadMATFile 34
57
May 2024 AutomationDesk Accessing MATLAB
Index
58
AutomationDesk Accessing MATLAB May 2024