Compiling c code to mex file

1 回表示 (過去 30 日間)
Shyam
Shyam 2013 年 4 月 18 日
This is an inbuilt example in matlab
i am getting an error while compiling c file:
mex getputvariable.c
C:\PROGRA~1\MATLAB\R2012B\BIN\MEX.PL: Error: 'getputvariable.c' not found.
Error using mex (line 206)
Unable to complete successfully.
What could be the problem?
  2 件のコメント
Kaustubha Govind
Kaustubha Govind 2013 年 4 月 19 日
Did you download the getputvariable.c file into your current folder? Is it listed when you run "ls" in the command window?
Shyam
Shyam 2013 年 4 月 22 日
編集済み: Shyam 2013 年 4 月 22 日
oops..the filename is actually mexgetputvariable.c...so i hav to type
mex mexgetputvariable.c
pls delete this question

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

回答 (1 件)

James Tursa
James Tursa 2013 年 4 月 19 日
If you are just using this example as a learning exercise, fine. But the example given is not a good way to go about things in general. Getting variables by name directly from a workspace and then replacing them will be prone to errors in the long run ... it binds you to exact variable names and from looking at the calling code you cannot tell at all what variables are used & changed by the mex call. It is much better to pass in variables through the argument list prhs and pass out results via plhs than it is to use this example. And a small nit about the code itself are these two lines:
array_ptr=mxCreateDoubleMatrix(1,1,mxREAL); /* size of 1x1 (scalar) */
array_ptr = mexGetVariable("base", array_name);
The first line is absolutely useless and in fact results in a memory leak since the pointer returned by the mxCreateDoubleMatrix call is wiped out on the very next line by the result of the mexGetVariable call. That first line should just be deleted.

カテゴリ

Help Center および File ExchangeMATLAB Compiler についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by