Using MATLAB code in the Engee environment¶
This example demonstrates how to call MATLAB functions in Engee, and how to apply and compare them to the environment functions.
Building curves in Engee:¶
Connecting the backend - a method for displaying graphics:
Pkg.add(["Statistics"])
using Plots
Generate two signals:
A = sin.(range(0, 2pi, length=100)')' # синусоида
B = @. sin(A) + 0.1 * randn() # зашумлённая синусоида
C = 1:1:100;
Display two signals on the graph:
plot(C,A)
plot!(C,B)
Calculate the correlation between the two signals by first connecting the library of statistical functions:
using Statistics
engee_cor = cor(A,B)
Calling MATLAB code from Engee¶
From Julia, you can call an arbitrary MATLAB command or function that will return a result.
Let's connect the MATLAB interface:
using MATLAB
Load signal data from Engee into the MATLAB kernel:
D = hcat(A,B)
A = D[:,1];
B = D[:,2];
mat"""
A = $A;
B = $B;
R = corrcoef(A,B);
"""
Calculating the correlation between two signals using MATLAB kernel function:
matlab_cor = mat"R; R()"
Comparison of results and calculation of the absolute error of the methods from MATLAB and Engee:
difference = abs(engee_cor[1,1] - matlab_cor[1,2])
println("Корреляция Engee: ", engee_cor[1,1], '\n', "Корреляция Matlab: ", matlab_cor[1,2], '\n', "Абсолютная погрешность: ", difference)
Calling a sinusoid with increasing frequency from MATLAB:
chirp = mat"chirp = dsp.Chirp('InitialFrequency', 0,'SamplesPerFrame', 500); chirp()"
plot(chirp)
Constructing a magic square:
mat"magic(3)"
The simplest arithmetic operations:
x = range(-10.0, stop=10.0, length=50)
y = range(2.0, stop=3.0, length=50)
mat"""
$u = $x + $y
$v = $x - $y
"""
plot(u,v)
Calling MATLAB files from Engee¶
Path to the folder opened in the file manager:
mat"cd $(@__DIR__)"
Running m-script:
mat"file"
mat"run('file.m')"
mat"""run("file.m")"""
Running a MATLAB function:
mat"fun(10,9)"
x = 12;
y = 13.12;
z = mat"fun($x,$y)"
z/10
Viewing the MATLAB workspace:
mat"whos"
Clearing the MATLAB workspace:
mat"clear"
mat"whos"
Conclusion:¶
This example has demonstrated the use of MATLAB functions in the Engee environment, their combined use, and the numerical difference between the methods used.