Using VBA
An important feature of mathlayer® is that it can be called from VBA functions.
Here we will show how to create a VBA function that uses mathlayer® to generate a matrix with uniform random numbers, stores it into a csv file and then displays the csv file.
Open VBA editor (ALT+F11) and paste the following code:
Here we will show how to create a VBA function that uses mathlayer® to generate a matrix with uniform random numbers, stores it into a csv file and then displays the csv file.
Open VBA editor (ALT+F11) and paste the following code:
Function mathlayertest() Dim out As Variant
out = Application.Run("m", "csvwrite('out.csv',rand(2,3))") out = Application.Run("m", "shell('out.csv')") End Function
Running this code opens the csv file where the matrix has been stored using your PC's default application for csv files (in this case notepad++):
Loading Data from Excel
Calling "Application.Run" with more than two arguments allows loading data from Excel to mathlayer® through VBA. The second argument defines the variable name. The additional arguments will determine the variable type:- The third argument, which has to be an Excel range, will define a matrix or a cell array.
- Adding a fourth argument will define a table. This fourth argument will be taken as column names for the table.
- A fifth argument will define row names for tables.