MatDeck provides an integration of text editing, computer programming in MatDeck script and Python, math, data visualization and several other features. MatDeck script is based on C++.

Here is an example which shows use and exchange of variables between MatDeck and Python. As MatDeck is based on C++, is there type match between variables? Here, in the example code there is tolist() to convert Python type of variable to list which can be recognized by c++. Is it possible to do that in a different manner?

Here is how FFT is calculated in MatDeck. This is MatDeck script.

nn := 4096 //length of the signal

x_in := normrandvec(0, 1, nn) //signal as random noise

X_in1 := fft1(x_in) 

freq := ynodes(f, 0, 1, nn) //frequency axis

graph := join_mat_cols(freq, abs(X_in1)) //Amplitude spectrum of the signal

ss := 0 //Variable defined in MatDeck to store result in Python

Here is how Python is used to calculate FFT. The Python code is written in MatDeck document, using MatDeck variables.

This is Python code in MatDeck

##py

from scipy.fftpack import fft #we need fft function

ss1 = fft(x_in)

ss=ss1.tolist() #convert to list which is converted in C++ vector

import matplotlib.pyplot as plt #It is possible to plot signal in Python, as well. 

plt.plot(freq, abs(ss1))

plt.grid()

plt.show()

###

// End of Python code

We can use variable ss in MatDeck to plot result.

graphP := join_mat_rows(freq, abs(ss))

What are natural conversions between MatDeck(C++) and Python?

0 Answers