Engee documentation

Import and export of variables

Engee supports writing and unloading variables in .mat and .jld2 formats:

  • .mat is the format used in MATLAB software.

  • .jld2 is the format used in Julia programming language.

To write variables in .mat or .jld format, select them in the variables window variables article 2 1 and right-click to bring up the context menu. From the menu, click Save as…​:

variables mat jld exp en

This will open the variable export window:

variables mat export 2 en

  1. Specify the name of the file that will contain the variables.

  2. Select the format of the exported file - MAT or JLD2.

  3. Trace the directory where the file will be saved.

  4. Set the path where the file will be saved. All folders in the Engee file browser will be displayed in this area.

  5. Go back from the current directory to the levels above, up to /user (the beginning of the Engee file browser path).

  6. Create a new folder in the directory of step 3.

The saved file in MAT or JLD2 format will appear in file browser img4. Double left-clicking on the saved file will import the variables into the Engee workspace. The imported variables will automatically be added to variable window variables article 2 1.

MAT

Use the MAT.jl package to work with .mat data in Julia (see MAT for details).

You can work with the MAT format programmatically, via script editor or command line. For example, consider the following code to read one variable from MAT:

using MAT # connecting the MAT library to work with .mat files
a = 1 # setting the variable a with a value of 1
file = matopen("/user/mat_file.mat") # open the mat_file.mat file for reading using the matopen function and create a file object
variable_mat = read(file, "a") # reads the variable "a" from a file of type MAT and assigns its value to the variable variable_mat
close(file) # closes the file

To write a variable to a MAT file, we use the code:

variable_1 = 1 # let's set the variable variable_1 and assign it the value 1
file = matopen("/user/new_mat_file.mat", "w") # opens the new_mat_file.mat file in writing mode ("w")
write(file, "variable_mat", variable_1) # writes the value of the variable variable_1 to the variable variable_mat in the file new_mat_file.mat
close(file) # closes the file

With this code we have written a variable to a MAT file. In a similar way, through the matwrite function, we can write a Dict (dictionary) in MAT format, using its keys as variable names:

mat_Dict = Dict(
"variable_1" => 1,
"variable_2" => -2,
"variable_3" => "Hello, world")
matwrite("/user/Dict.mat", mat_Dict)

The code will create a Dict.mat file containing the dictionary with the variable names.

You can use the compress data compression argument set to true (by default disabled, false) to write large data in MAT format:

mat_Dict = Dict(
"variable_1" => 1,
"variable_2" => -2,
"variable_3" => "Hello, world")
matwrite("/user/Dict.mat", mat_Dict; compress = true)

JLD2

Use the JLD2.jl package to work with .jld2 data in Julia (see JLD2.jl for details ).

Load the JLD2 module:

import Pkg; # importing a package manager
Pkg.add("JLD2") # adding the JLD2 package

The JLD2.jl package supports function interfaces like jldsave. For example:

using JLD2 # loading the module

x = 1
y = 2
z = 42

# The simplest case:
jldsave("example.jld2"; x, y, z)
# this is equivalent to
jldsave("example.jld2"; x=x, y=y, z=z)

# New names can be assigned only to parts of the arguments.
jldsave("example.jld2"; x, a=y, z)

# and to create complete confusion, you can do this
jldsave("example.jld2"; z=x, x=y, y=z)

If you want to save only one object in a file for later loading, you can use the save_object and load_object functions. For example:

save_object(filename, x) # saves the x object in a new JLD2 file in filename, if the file exists in this path, it will be overwritten.

load_object(filename, x) # loads object x