mexmat.c

来自「非均匀有理B样条的matlab程序」· C语言 代码 · 共 44 行

C
44
字号
// Useful functions for accessing and manipulating matlab data structures.
// =======================================================================

#include "mexmat.h"

// convert c vector to c matrix.
double **vec2mat(double *vec, int nrows, int ncols) 
{
  int col;
  double **mat;

  mat = (double**) mxMalloc (ncols*sizeof(double*));
  mat[0] = vec;
  for (col = 1; col < ncols; col++)
    mat[col] = mat[col-1] + nrows;  
  return mat;
}

// create a new c matrix
double **matrix(int nrows, int ncols) 
{
  int col;
  double **mat;

  mat = (double**) mxMalloc (ncols*sizeof(double*));
  mat[0] = (double*) mxMalloc (nrows*ncols*sizeof(double));
  for (col = 1; col < ncols; col++)
    mat[col] = mat[col-1] + nrows;  
  return mat;
}

void freevec2mat(double **mat)
{
  mxFree(mat);
}

void freematrix(double **mat)
{
  mxFree(mat[0]);
  mxFree(mat);
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?