Hi everyone,
I started working with mex on matlab to build a c code and I wrote a very simple code (main.c) to begin with :
#include "stdio.h"
#include "stdlib.h"
#include "mex.h"
void main()
{
mexPrintf("Hello world");
}
when I type mex main.c in a matlab script everything goes well and I have this message:
"Building with 'gcc'.
MEX completed successfully."
but I don't see the message "Hello world", I tried printf() too without success, does anyone know why the message doesn't appear on the matlab window please ?
Thanks in advance for your help.
-J

 採用された回答

Jan
Jan 2017 年 7 月 17 日

2 投票

How do you call this code from where? Without a mexFunction() it cannot be called from Matlab, because this is the entry function (and not "main()"). If you call it from somewhere else, the code has no connection to Matlab's command window. printf() works in a console application, but it is not clear, how you have compiled the code: "mex main.c" would require a mexFunction to work, but you should see a corresponding error message.
Working:
// main.c
#include "mex.h"
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
mexPrintf("Hello world!\n");
}
Now compile it by "mex main.c" and run it by typing main in the command window.

1 件のコメント

JM
JM 2017 年 7 月 19 日
You're absolutely right Jan Simon, I added a mexFunction and it worked, thanks you so much !

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Write C Functions Callable from MATLAB (MEX Files) についてさらに検索

タグ

質問済み:

JM
2017 年 7 月 16 日

編集済み:

2017 年 7 月 19 日

Community Treasure Hunt

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

Start Hunting!

Translated by