A matrix can be passed to the user defined function by "pass by reference" method i.e. basically by passing a pointer that stores(or points to ) the address of the first element of the matrix. In the code example pasted below, the main fuction passes a matrix to a function "print_matrix" that prints all the elements of the matrix:

#include<def21369.h> #include<stdio.h>

void print_matrix(int *m, int r, int c);

int main() { int i;

int m[3][4]={1,2,3,4,5,6,7,8,9,10,11,12};

int* m_ptr=(int*)((&m));

print_matrix(m_ptr, 3, 4);

return 0; }

void print_matrix(int *m, int r, int c) { int i,j;

for(i=0;i<r;i++) { printf("\n");

for(j=0;j<c;j++) { printf(" %d",*m++); } }

}

The output of this code would be:

1 2 3 4 5 6 7 8 9 10 11 12

The matrix library functions provided with VisualDSP uses similar method.

In this method, you have to pass the number of rows and column information seperately. Another way could be to define a seperate data structure "MATRIX" that has the actual data, no. of rows, no. of columns as its member variables. You could then pass the whole object of the data type "MATRIX" as reference as a single parameter to a function.

Hi Milos,

A matrix can be passed to the user defined function by "pass by reference" method i.e. basically by passing a pointer that stores(or points to ) the address of the first element of the matrix. In the code example pasted below, the main fuction passes a matrix to a function "print_matrix" that prints all the elements of the matrix:

#include<def21369.h>

#include<stdio.h>

void print_matrix(int *m, int r, int c);

int main()

{

int i;

int m[3][4]={1,2,3,4,5,6,7,8,9,10,11,12};

int* m_ptr=(int*)((&m));

print_matrix(m_ptr, 3, 4);

return 0;

}

void print_matrix(int *m, int r, int c)

{

int i,j;

for(i=0;i<r;i++)

{

printf("\n");

for(j=0;j<c;j++)

{

printf(" %d",*m++);

}

}

}

The output of this code would be:

1 2 3 4

5 6 7 8

9 10 11 12

The matrix library functions provided with VisualDSP uses similar method.

In this method, you have to pass the number of rows and column information seperately. Another way could be to define a seperate data structure "MATRIX" that has the actual data, no. of rows, no. of columns as its member variables. You could then pass the whole object of the data type "MATRIX" as reference as a single parameter to a function.

Hope this helps.

Thanks,

Mitesh