diff options
Diffstat (limited to 'Examples/scilab/matrix2/example.c')
-rw-r--r-- | Examples/scilab/matrix2/example.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/Examples/scilab/matrix2/example.c b/Examples/scilab/matrix2/example.c index 476067df9..232c88824 100644 --- a/Examples/scilab/matrix2/example.c +++ b/Examples/scilab/matrix2/example.c @@ -29,12 +29,12 @@ void squareDoubleMatrix(double *inputMatrix, int nbRow, int nbCol, double** resu } } -void getDoubleMatrix(double **resultMatrix, int *nbRowRes, int *nbColRes) +void getDoubleMatrix(int nbRow, int nbCol, double **resultMatrix, int *nbRowRes, int *nbColRes) { int i; int size; - *nbRowRes = 5; - *nbColRes = 3; + *nbRowRes = nbRow; + *nbColRes = nbCol; size = (*nbRowRes) * (*nbColRes); *resultMatrix = (double*) malloc(size * sizeof(double)); for (i=0; i<size; i++) @@ -43,6 +43,30 @@ void getDoubleMatrix(double **resultMatrix, int *nbRowRes, int *nbColRes) } } +void extractDoubleMatrix(double *inputMatrix, int nbRow, int nbCol, int* indexes, int nbIndexes, double **resultMatrix, int *nbRowRes, int *nbColRes) +{ + if (nbIndexes < 0) + { + int sz = nbRow * nbCol; + *nbRowRes = sz; + *nbColRes = 1; + + *resultMatrix = malloc(sz * sizeof(double)); + memcpy(*resultMatrix, inputMatrix, sz * sizeof(double)); + } else { + int i; + + *nbRowRes = nbIndexes; + *nbColRes = 1; + + *resultMatrix = malloc(nbIndexes * sizeof(double)); + for (i = 0; i < nbIndexes; i++) + { + (*resultMatrix)[i] = inputMatrix[indexes[i]]; + } + } +} + // Integer matrix functions int sumIntegerMatrix(int *inputMatrix, int nbRow, int nbCol) |