search for: printmatrix

Displaying 2 results from an estimated 2 matches for "printmatrix".

2013 Dec 06
3
Matrix memory layout R vs. C
...in R, it's a concatenation of the columns. That leads to the problem. that an R-matrix, for example 123 456 789 is seen by C as 147 258 369 and vice versa. Here's an example of C code that simply prints the matrix it gets from R: #include <stdlib.h> #include "R.h" void printMatrix(int *mPtr, int *m, int *n) { int (*matrix)[*n] = mPtr; int j,k; for(j = 0; j < *m; j++){ for(k = 0; k < *n; k++) { printf("%d", matrix[j][k]); } printf("\n"); } } And here's what happens when I call the function in R: > m <- 3;...
2010 Jan 23
1
matrix to a C function
Hi the list, Is there a way to give a matrix to a C function, and then to use it as a matrix ? I write a function to print a matrix, but I use it as a vector : 1. void printMatrix(double *mTraj,int *nbCol, int *nbLigne){ 2. int i=0,j=0; 3. for(i=0 ; i < *nbLigne ; i++){ 4. for(j=0 ; j < *nbCol ; j++){ 5. Rprintf(" %f",mTraj[i * *nbCol + j]); 6. } 7. Rprintf("\n"); 8. } 9. } I would like to use it as a matrix (line 5...