How to convert tables into matrices

Table-valued functions in finaquant .net libraries

How to convert tables into matrices

Postby windy » 12 Oct 2013, 19:28

Hi
I installed the library, demo functions are working fine for me.
is it possible to convert tables into matrices, and vice versa? how?
windy
windy
 
Posts: 3
Joined: 19 Sep 2013, 19:41

Re: How to convert tables into matrices

Postby finaquant » 15 Oct 2013, 21:12

Yes, it is possible to convert tables into matrices, and matrices into tables.

A) Converting a table of type MatrixTable into matrices
Image
By using MatrixTable properties:
- KeyFigValues for getting matrix contained by table with floating numbers (all values of key figure fields in table)
- NumAttribValues for getting matrix contained by table with integer numbers (all values of numeric attributes in table)
- TextAttribValues for getting matrix contained by table with string values (all values of text attributes in table)

Example:
Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. KeyMatrix M = CostTable.KeyFigValues
GeSHi ©


See advanced table functions TransformSubTables and MatrixFunctionRouter for applying matrix functions on subtables.

B) Converting a matrix (or matrices with same row-size) into a MatrixTable
See table function MatrixTable.CreateTableWithMatrices (A and B)
and demo function named Create_MatrixTable_manually() in MS Visual Studio file FinaquantCalcsStarter for examples.

Product page of finaquant® calcs with downloads:
finaquant.com/products/finaquantcalcs

Example:
Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. // Create a table with value matrices for each field type
  2. // Define structure (i.e. fields) of table
  3. var tfields4 = TableFields.CreateEmptyTableFields(md);
  4. TableFields.AddNewField(tfields4, "category");
  5. TableFields.AddNewField(tfields4, "animal");
  6. TableFields.AddNewField(tfields4, "population");
  7. TableFields.AddNewField(tfields4, "year");
  8.  
  9. // generate value matrices for each field type
  10. // create 3x2 text matrix
  11. TextMatrix tM = TextMatrix.CreateMatrixWithElements(3, 2,
  12.     "mammals", "tiger",
  13.     "mammals", "lion",
  14.     "mammals", "leopard"
  15.     );
  16. // create 3x1 numeric matrix
  17. NumMatrix nM = NumMatrix.CreateMatrixWithElements(3, 1,
  18.     2010, 2011, 2012);
  19. // create 3x1 key figure matrix
  20. KeyMatrix kM = KeyMatrix.CreateMatrixWithElements(3, 1,
  21.     1200.0, 2500.0, 3500.0);
  22.  
  23. // create table with matrices representing field values
  24. var table4 = MatrixTable.CreateTableWithMatrices_A(tfields4, tM, nM, kM);
GeSHi ©
User avatar
finaquant
 
Posts: 61
Joined: 16 Sep 2013, 18:37


Return to Table Functions

Who is online

Users browsing this forum: No registered users and 1 guest

cron