MatrixInvert

Prev Next Home Home Table Of Contents Index

MatrixInvert (2D Array)

MatrixInvert reverses the coordinates of a 2-dimensional array. This is useful when used with ReadAscTextFile to reverse the field and record layout.


Example:
var Data NameList

ReadAscTextFile('PHONE.LST',Data) MatrixInvert Data NameList = Data[1] ;makes an array from field 1

A common use of this command is sorting a 2 dimensional array by one of it's key fields. Suppose you wanted to sort by the second field. Here's how you might do it.


Example:
var Customers Names

Customers[1] = Set[200,"Joe","888-5329"] Customers[2] = Set[201,"Adam","866-9823"] Customers[3] = Set[202,"Kate","862-9236"] ; The above creates a 2-dimensional array called Customers

MatrixInvert Customers ; here, the array is inverted Names = Customers[2] MatrixInvert Customers ; here, the array is reinverted SortArrayLinked(Customers,Names) ;the array Customers is sorted alphabetically by Names Loop Customers Loop LoopVal Write LoopVal ' ' ; the values of the array Customers is printed out EndLoop Writeln EndLoop

In the above example, the result is: 201 Adam 866-9823 200 Joe 888-5329 202 Kate 862-9236

The MatrixInvert will take a matrix like: 200 Joe 888-5329 201 Adam 866-9823 202 Kate 862-9236

and invert it to: 200 201 202 Joe Adam Kate 888-5329 866-9823 862-9236

See Also: SortArrayLinked

Category: Array

Prev Next Home Home Table Of Contents Index

Sponsors
Shopping
Forum
Forum
email
EMail
Index
Index
Home
Home