mexPrintf to standard error

6 ビュー (過去 30 日間)
Jim Hokanson
Jim Hokanson 2016 年 12 月 5 日
コメント済み: Jim Hokanson 2016 年 12 月 6 日
Is it possible to direct the output of mexPrintf to standard error? I'd like something like in Matlab where you can do fprintf(2,...) to print out error code.
  2 件のコメント
James Tursa
James Tursa 2016 年 12 月 6 日
Do you mean dynamically redirect all mexPrintf output at runtime? I.e., used to go to screen but now goes to standard error?
Jim Hokanson
Jim Hokanson 2016 年 12 月 6 日
I am looking for a command that works like fprintf(2,...) (Matlab) but for mex. Something that prints to the Matlab command window, but in red, rather than in black.

サインインしてコメントする。

採用された回答

James Tursa
James Tursa 2016 年 12 月 6 日
Brute force? I can't think of another way to get at the MATLAB standard error printing. E.g.,
/* Includes ----------------------------------------------------------- */
#include "mex.h"
#include <stdio.h>
/* Global variables --------------------------------------------------- */
char s[2000];
mxArray *rhs[2];
/* Functions ---------------------------------------------------------- */
void mexPrintf2(char *s)
{
rhs[1] = mxCreateString(s);
mexCallMATLAB(0,NULL,2,rhs,"fprintf");
mxDestroyArray(rhs[1]);
}
/* Gateway ------------------------------------------------------------ */
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
rhs[0] = mxCreateDoubleScalar(2.0);
sprintf(s,"This is a test\nThis is only a test\nIn an actual emergency ...\n");
mexPrintf2(s);
sprintf(s,"The number %d + %d = %d\n",1,2,1+2);
mexPrintf2(s);
mxDestroyArray(rhs[0]);
}
  1 件のコメント
Jim Hokanson
Jim Hokanson 2016 年 12 月 6 日
:) Ha, why not.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWrite C Functions Callable from MATLAB (MEX Files) についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by