⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mex_strmat.c

📁 本人收集的一些有关matlab的代码程序设计 也不知道改选什么分类
💻 C
字号:
#include "matrix.h"
/*Function mex_strmat*/
void mexFunction( int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[])
{
   char *my_str;
   mxChar *xp;
   int n_mystr, i, j, *ndims, m, n;
   if (nrhs!=1) mexErrMsgTxt("Wrong number of input arguments!");
   if (nlhs>1) mexErrMsgTxt("Too many output arguments!");
   if (!mxIsChar(prhs[0])) mexErrMsgTxt("String input is required!");
   n_mystr=mxGetNumberOfElements(prhs[0])+1;
   my_str=mxCalloc(n_mystr, sizeof(char));
   ndims=mxGetDimensions(prhs[0]); m=ndims[0];
   n=mxGetNumberOfDimensions(prhs[0]); 
   mxGetString(prhs[0], my_str, n_mystr);
   if (nlhs==1) {
      plhs[0]=mxCreateCharArray(n,ndims); 
      xp=(mxChar *) mxGetData(plhs[0]); 
      for (i=0; i<n_mystr; i++) xp[i]=my_str[i]; 
   }
   else{
      for (j=0; j<m; j++){
         for (i=j; i<n_mystr; i+=m) mexPrintf("%c",my_str[i]);
         mexPrintf("\n");
      }
   }
   mxFree(my_str);
}

⌨️ 快捷键说明

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