我在here中显示的示例中创建了一个MEX文件中的稀疏矩阵。现在我如何从MATLAB整体访问这个矩阵。从MATLAB中访问在MEX中创建的稀疏矩阵
#define NZMAX 4
#define ROWS 4
#define COLS 2
int rows=ROWS, cols=COLS;
mxArray *ptr_array; /* Pointer to created sparse array. */
static double static_pr_data[NZMAX] = {5.8, 6.2, 5.9, 6.1};
static int static_ir_data[NZMAX] = {0, 2, 1, 3};
static int static_jc_data[COLS+1] = {0, 2, 4};
double *start_of_pr;
int *start_of_ir, *start_of_jc;
mxArray *array_ptr;
/* Create a sparse array. */
array_ptr = mxCreateSparse(rows, cols, NZMAX, mxREAL);
/* Place pr data into the newly created sparse array. */
start_of_pr = (double *)mxGetPr(array_ptr);
memcpy(start_of_pr, static_pr_data, NZMAX*sizeof(double));
/* Place ir data into the newly created sparse array. */
start_of_ir = (int *)mxGetIr(array_ptr);
memcpy(start_of_ir, static_ir_data, NZMAX*sizeof(int));
/* Place jc data into the newly created sparse array. */
start_of_jc = (int *)mxGetJc(array_ptr);
memcpy(start_of_jc, static_jc_data, NZMAX*sizeof(int));
/* ... Use the sparse array in some fashion. */
/* When finished with the mxArray, deallocate it. */
mxDestroyArray(array_ptr);
也同时存储在static_pr_data
,ic_data
和jc_data
值是有必要存储在列优先格式值是多少?是否有可能以行格式存储(因为它会加快我的计算)?
请张贴相关的代码** **在这里,而比链接。 – PengOne 2011-05-27 15:03:02
会听从你的意见克里斯! – koder 2011-05-29 07:41:49