Spec-Zone.ru › Octave 6

A.2.3 Строки символов в MEX-файлах

Поскольку MEX-файлы не различают одинарные и двойные кавычки, как Octave, в использовании строк и матриц символов, возможно, меньше сложности. Пример их использования, аналогичный демонстрации в stringdemo.cc, приведен в файле mystring.c, как показано ниже.

#include <string.h>
#include "mex.h"

void
mexFunction (int nlhs, mxArray *plhs[],
             int nrhs, const mxArray *prhs[])
{
  mwSize m, n;
  mwIndex i, j;
  mxChar *pi, *po;

  if (nrhs != 1 || ! mxIsChar (prhs[0])
      || mxGetNumberOfDimensions (prhs[0]) > 2)
    mexErrMsgTxt ("ARG1 must be a char matrix");

  m = mxGetM (prhs[0]);
  n = mxGetN (prhs[0]);
  pi = mxGetChars (prhs[0]);
  plhs[0] = mxCreateNumericMatrix (m, n, mxCHAR_CLASS, mxREAL);
  po = mxGetChars (plhs[0]);

  for (j = 0; j < n; j++)
    for (i = 0; i < m; i++)
      po[j*m + m - 1 - i] = pi[j*m + i];
}

Пример ожидаемого вывода:

mystring (["First String"; "Second String"])
⇒ Second String
   First String

Другие функции интерфейса MEX для работы со строками символов — mxCreateString, mxArrayToString, и mxCreateCharMatrixFromStrings. В MEX-файле строка символов рассматривается как вектор, а не матрица. Возможно, это произвольное различие, поскольку данные в mxArray для матрицы в любом случае расположены последовательно.

© 1996–2022 The Octave Project Developers
Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.
Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions.
https://docs.octave.org/v6.4.0/Character-Strings-in-Mex_002dFiles.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API