« Run fmsadmin from scr… | Home | MBS Plugin Release Sc… »

Matrix functions for FileMaker

Did you ever wish you have the possibility to use a 2D array as a data structure in FileMaker? If the answer is yes, we have very good news for you, with the MBS FileMaker Plugin 9.2 your wish come true.

In this blog entry I want to show you some functions for the matrix.

At first you create a matrix and fill it with values. We make a 3 by 3 matrix:

Set Variable [ $matrix ; Value: MBS("Matrix.New";3;3) ]
Set Variable [ $r ; Value: MBS( "Matrix.SetColumn"; $matrix; 0;"15¶07¶92" ) ]
Set Variable [ $r ; Value: MBS( "Matrix.SetColumn"; $matrix; 1;"17¶3¶60" ) ]
Set Variable [ $r ; Value: MBS( "Matrix.SetColumn"; $matrix; 2;"15¶1¶87" ) ]

We fill the matrix by single columns with values but you can fill in a similar way by rows (Matrix.SetRow) or single values by navigate with columns- and row numbers (Matrix.SetValue).
With all this functions you can later change data in the matrix.

You can output the matrix with MBS("Matrix.GetText"; $matrix) but the layout of the output is confusing with more then 1 column, because by default the delimiter is an empty text. You can pass Char(9) for using tab character or maybe better use the Matrix.CSV function. There you can define which part of the matrix should be printed and define your own row and column separators, which make it easier to read the output. Default delimiters are new line and semicolon characters.

You can clone a matrix with Matrix.Clone function:

Set Variable [ $CloneMatrix ; Value: MBS("Matrix.Clone";$Matrix) ]

You may need a copy if you want to modify the matrix, but keep the old state somewhere. The function copy the matrix and returns a new reference number. If you are not sure whether your matrix have the right size for a calculation, you can test it. Here is a code example for testing if the matrix have same amount of rows like amount of columns:

If [ MBS("Matrix.Height";$matrix) = MBS("Matrix.Width"; $Matrix) ]
  Show Custom Dialog [ "The matrix is quadratic"; "The number of rows and columns is the same!" ]
End If

If you want to sum all numbers of the matrix, at first you can sum all single columns and then sum the results.

Set Variable [ $a ; Value: MBS( "Matrix.Sum"; $matrix; 0 ) ]
Set Variable [ $b ; Value: MBS( "Matrix.Sum"; $matrix; 1 ) ]
Set Variable [ $c ; Value: MBS( "Matrix.Sum"; $matrix; 2 ) ]
Set Variable [ $sum ; Value: $a + $b + $c ]

If you want to add some rows or columns, you can do it with the Matrix.AddColumn, Matrix.AddColumns, Matrix.AddRow and Matrix.AddRows functions easily.

I wish you fun with this 2D data structure. If you have questions or need more information about the plugin please don’t hesitant to contact us.
By Stefanie Juchmes Claris FileMaker Plugin
28 05 19 - 09:43