To be able to use the C-code you have to compile it from Matlab comand line with the comand
Expand|Select|Wrap|Line Numbers
- mex myfile.c
Now if I compile I get the following error:
Expand|Select|Wrap|Line Numbers
- >> mex givegradient.c
- Warning: You are using gcc version "4.1.2". The earliest gcc version supported
- with mex is "3.4.0". The latest version tested for use with mex is "3.4.5".
- To download a different version of gcc, visit http://gcc.gnu.org
- givegradient.c:2: error: expected identifier or ‘(’ before ‘/’ token
- givegradient.c:16: error: expected identifier or ‘(’ before ‘/’ token
- givegradient.c:142: error: expected declaration specifiers or ‘...’ before ‘/’ token
- givegradient.c:143: error: expected declaration specifiers or ‘...’ before ‘/’ token
- givegradient.c:144: error: expected declaration specifiers or ‘...’ before ‘/’ token
- givegradient.c:147: error: conflicting types for ‘mexFunction’
- /usr/local/matlab/extern/include/mex.h:148: error: previous declaration of ‘mexFunction’ was here
- givegradient.c: In function ‘mexFunction’:
- givegradient.c:156: error: ‘nrhs’ undeclared (first use in this function)
- givegradient.c:156: error: (Each undeclared identifier is reported only once
- givegradient.c:156: error: for each function it appears in.)
- givegradient.c:159: error: ‘prhs’ undeclared (first use in this function)
- givegradient.c:159: warning: assignment discards qualifiers from pointer target type
- givegradient.c:166: error: ‘plhs’ undeclared (first use in this function)
- mex: compile of 'givegradient.c' failed.
- ??? Error using ==> mex
- Unable to complete successfully.
Expand|Select|Wrap|Line Numbers
- /* $Revision: 1.1 $ */
- // Automatically generated by Matlab AppWizard version 1.0
- //
- // This is the gateway routine for a MATLAB Math/Graphics Library-based
- // C MATLAB MEX File.
- #include "mex.h"
- #include <math.h>
- #define K 10.0
- #define MAX(A,B) ((A)>(B)?(A):(B))
- #define MIN(A,B) ((A)<(B)?(A):(B))
- #define SGN(A) ((A)>0?1.:-1.)
- #define ABS(A) ((A)>0?(A):-(A))
- etc.
I think it must be a compiler thing because the code worked with no problems on windows...
Thanks for any help