I have forgotten
my Password

Or login with:

  • Facebookhttp://facebook.com/
  • Googlehttps://www.google.com/accounts/o8/id
  • Yahoohttps://me.yahoo.com
get GPL
COST (GBP)
this unit 0.30
sub units 0.00
+
0
ComputingArray

Matrix

viewed 15907 times and licensed 367 times
Dynamically allocates a zero-based 2D block (matrix) of data.
Controller: will

Interface

C++

Matrix

 
template<class T>T**matrixlongRows
longColumns )[inline]
Dynamically allocates a zero-based 2D block of memory. This memory block is continuous, and is in column then row order

MISSING IMAGE!

1/matrix-969.png cannot be found in /users/1/matrix-969.png. Please contact the submission author.

For example, with an allocation of the type:
float **a = matrix<float>(2,3);
Then <tt>a[1][4] === a[2][0]</tt>.

The opposite of this function is <em> free_matrix </em>.

Example

#include <codecogs/computing/array/matrix.h>
 
int main()
{
  // allocate some memory, 5 rows, 3 columns
  int **A = Array::matrix<int>(5,3);
 
  // initialize with some data
  for(int j=0; j<5; j++)
    for(int i=0; i<3; i++)
      A[j][i] = i*j;
 
  // convert to one-dimensional array  
  int *B = A[0];
  for(int i=0; i<15; i++)
    printf(" %d", B[i]);
 
  // tidy up
  Array::free_matrix(A);
}
Output:
1 2 3 2 4 6 3 6 9 4 8 12 5 10 15

Note

You should always use <em> free_matrix </em> to de-allocate memory allocated to this structure.

Parameters

RowsThe 2nd dimension of a matrix.
ColumnsThe 1st (primary) dimension of a matrix.

Authors

Will Bateman (February 2005)
Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.


Free Matrix

 
template<class T>voidfree_matrixT**Matrix )[inline]
Removes any dynamically allocated memory for a 2D structure from the stack. This function is usually used on data structures created using matrix<>, though it can also be used on other 2D types, so long as the memory is continuously allocated.

The opposite of this function is <em> matrix </em>

Parameters

Matrixis the 2D data structure to delete.

Authors

Will Bateman (February 2005)
Source Code

Source code is available when you agree to a GP Licence or buy a Commercial Licence.

Not a member, then Register with CodeCogs. Already a Member, then Login.