MATLAB CODE TO C CODE

Hi Frnds, i coverted the matlab code to c code using codgen ,while i'm running the code in turbo c i'm facing the problem. its showing 25 errors, most of them showing as decleration syntax error. pls help me out thank you

回答(6 个)

Walter Roberson
Walter Roberson 2012-1-23

1 个投票

According to one of your other posts, you are using R2011a. Turbo C is not a supported compiler for R2011a. See http://www.mathworks.com/support/compilers/R2011a/win32.html

5 个评论

so through which compailer ican check my code. . .
Have you run through an example such as is described at http://www.mathworks.com/help/toolbox/coder/gs/bsumqa0.html in order to verify that the basics work for you?
Perhaps you could describe more specifically the errors that you see when you use Turbo C.
the following are the few lines where i'm getting errors in my c code.
static emlrtRSInfo emlrtRSI = { 27, "pca", "C:/Users/aeamt/Desktop/PCA/pca.m" };
static emlrtRSInfo b_emlrtRSI = { 30, "pca", "C:/Users/aeamt/Desktop/PCA/pca.m" };
static emlrtRSInfo c_emlrtRSI = { 32, "pca", "C:/Users/aeamt/Desktop/PCA/pca.m" };
static emlrtRSInfo d_emlrtRSI = { 36, "mean", "C:/Program Files/MATLAB/R2011a/toolbox/eml/lib/matlab/datafun/mean.m" };
static emlrtRSInfo h_emlrtRSI = { 15, "eml_error", "C:/Program Files/MATLAB/R2011a/toolbox/eml/lib/matlab/eml/eml_error.m" };
static emlrtRSInfo i_emlrtRSI = { 37, "mpower", "C:/Program Files/MATLAB/R2011a/toolbox/eml/lib/matlab/ops/mpower.m" };
static emlrtRSInfo j_emlrtRSI = { 40, "power", "C:/Program Files/MATLAB/R2011a/toolbox/eml/lib/matlab/ops/power.m" };
static emlrtRSInfo k_emlrtRSI = { 15, "eml_error", "C:/Program Files/MATLAB/R2011a/toolbox/eml/lib/matlab/eml/eml_error.m" };
static emlrtRSInfo l_emlrtRSI = { 14, "sqrt", "C:/Program Files/MATLAB/R2011a/toolbox/eml/lib/matlab/elfun/sqrt.m" };
static emlrtMCInfo emlrtMCI = { 15, 19, "eml_error", "C:/Program Files/MATLAB/R2011a/toolbox/eml/lib/matlab/eml/eml_error.m" };
static emlrtMCInfo b_emlrtMCI = { 15, 5, "eml_error", "C:/Program Files/MATLAB/R2011a/toolbox/eml/lib/matlab/eml/eml_error.m" };
static emlrtMCInfo c_emlrtMCI = { 15, 19, "eml_error", "C:/Program Files/MATLAB/R2011a/toolbox/eml/lib/matlab/eml/eml_error.m" };
static emlrtMCInfo d_emlrtMCI = { 15, 5, "eml_error", "C:/Program Files/MATLAB/R2011a/toolbox/eml/lib/matlab/eml/eml_error.m" };
static emlrtBCInfo emlrtBCI = { 1, 3, 12, 7, "", "pca", "C:/Users/aeamt/Desktop/PCA/pca.m", 0 };
static emlrtBCInfo b_emlrtBCI = { -1, -1, 53, 6, "Cont", "pca", "C:/Users/aeamt/Desktop/PCA/pca.m", 0 };
static emlrtBCInfo c_emlrtBCI = { 1, 3, 53, 14, "te", "pca", "C:/Users/aeamt/Desktop/PCA/pca.m", 0 };
static emlrtBCInfo d_emlrtBCI = { 1, 1, 46, 7, "b", "pca", "C:/Users/aeamt/Desktop/PCA/pca.m", 0 };
static emlrtBCInfo e_emlrtBCI = { 1, 1, 43, 3, "Q", "pca", "C:/Users/aeamt/Desktop/PCA/pca.m", 0 };
static emlrtBCInfo f_emlrtBCI = { 1, 9, 12, 7, "", "pca", "C:/Users/aeamt/Desktop/PCA/pca.m", 0 };
static emlrtBCInfo g_emlrtBCI = { 1, 9, 12, 7, "", "pca", "C:/Users/aeamt/Desktop/PCA/pca.m", 0 };
for all the above lines it is showing the same error as DECELERATION SYNTAX ERROR".
That those are valid declaration syntax in C99, but I do not recall for certain whether they were valid in C89. I do find a number of locations that indicate that Turbo C was C89 at most (and possibly not even all of that), indicating that you will probably need to find a later compiler.
What is your target system that you are compiling for (that the code will be run on)? If it is MS Windows then use one of the compilers listed in the link I gave above.
ya thank you, i'll try with different compiler

请先登录,再进行评论。

Rajesh
Rajesh 2012-1-24

1 个投票

mr.Walter Roberson i"m jus giving the following command after correcting the errors in my .m code.and it'll genrate the c code for me . .
codegen -c (file name).
Kaustubha Govind
Kaustubha Govind 2012-1-20

0 个投票

Perhaps you are not specifying the correct compiler options? Make sure to use the codegen -v (verbose) option to see the exact compiler/linker commands that need to be used.

4 个评论

thanks for ur help kausthubh. i tried with that option codegen -v (my file name). its genrating a codegen file but i couldn't find anything. All i could see is , in that bulidinfo its showing the compailer as cll. hz to find the exact compiler.
thanks
Rajeshkumar.c
Have you run "mex -setup"? What compiler did you choose?
i'm not running any mex -setup, i'm getting my c code through the following syntax
codegen -c (my filename).
sorry previously i gave wrong info , actually i have run mex-setup and i selected lcc-win 32

请先登录,再进行评论。

Ahmed
Ahmed 2012-1-25

0 个投票

Dear Rajesh
I have the same problem but when I used you command the following error appeared:
Could not locate the MEX compiler options file mexopts.bat. Run mex -setup to select the MEX compiler and create the MEX options file. Use help codegen for more information on using this command. Error using codegen
How to run mex -setup??

1 个评论

At the MATLAB command prompt, type in the command
mex -setup
and press return.

请先登录,再进行评论。

Ahmed
Ahmed 2012-1-29

0 个投票

Dear Rajesh
I have the following error after writing the command codegen -c (NN_modify)
??? Unable to locate function '(NN_modify)'.
Code generation failed: Open error report. Error using codegen
I don't have any functions in my code

1 个评论

It seems unlikely to me that the '(' and ')' would be part of the syntax.

请先登录,再进行评论。

Ahmed
Ahmed 2012-1-29

0 个投票

Dear Walter
In my code I'm using the following lines:
load('input.mat');
load('target.mat');
after correcting the command line as you recommended, errors changed to:
??? This text contains non-empty top-level expressions. It appears to be a script.
Error in ==> NN_modify Line: 1 Column: 1
Code generation failed: Open error report.
Error using codegen

2 个评论

codegen can only compile functions, not scripts. You will have to add
function NN_Modify
as the first line.
i’m converting Matlab code to static c code, i found two ways to convert the code. Both are producing diff code, I just want to know which the correct way of code conversion. following the two commends ,
codegen -c pca
coder -new pca.prj
thanks
Rajeshkumar.c

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Dimensionality Reduction and Feature Extraction 的更多信息

产品

标签

提问:

2012-1-20

Community Treasure Hunt

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

Start Hunting!

Translated by