mathlayer from Excel

From Cells: Single Line

You can write scripts directly in worksheet cells. Calling "m" function on these cells allows running the scripts.

If you want for instance to create a 5x3 matrix with uniform random numbers, you can write in a cell:

x = rand(5,3)

And from a different cell call function "m":



mathlayer returns information on the objects created:

[x:5x3 double]

in this case a 5x3 matrix of doubles named x.

From Cells: Multiple Lines

In order to execute multiple lines of script directly from Excel you have two options: writing the full script within a single cell or spreading the lines of code in multiple cells.

Let's run the following script:

z = zeros(100)
for i=1:100
    for j=1:100
        z(i,j) = sin(i/12) + cos(j/12)
    end
end

from a single cell:



from multiple cells:



we get the same output:

[z:100x100 double][i:100][j:100]

Getting Data in Excel

You simply need to add hashtag # symbol after a variable name to output its values.

In order to output matrix z (as defined in script above) into Excel you run "z#" on a range of cells:



in order to get matrix output into Excel you need to press CTRL+SHIFT+ENTER:



More information about array formulas in Excel.

Loading Data from Excel

Calling "m" function with more than one argument allows loading data from Excel to mathlayer: first argument defines variable name and second argument must be an Excel range with the data to load.
  • Matrix


  • Cell array


  • Table: third argument must be an Excel range with variable names and fourth argument (optional) defines row names.






Console

You can also display data in mathlayer console using disp function: