我按照此处显示的示例在 MEX 文件中创建了一个稀疏矩阵。现在我如何从整个 MATLAB 访问这个矩阵。
#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