how to run c program file in matlab
1 回表示 (過去 30 日間)
古いコメントを表示
Hi i wish to call function written in .c in matlab. I installed sdk. I tried with mex filename.c and got the following error
C:\Users\Deepa\Documents\MATLAB\treevalc.c(26) : warning C4101: 'cid' : unreferenced local variable
C:\Users\Deepa\Documents\MATLAB\treevalc.c(92) : error C2143: syntax error : missing ';' before 'type'
C:\Users\Deepa\Documents\MATLAB\treevalc.c(94) : error C2143: syntax error : missing ';' before 'type'
C:\Users\Deepa\Documents\MATLAB\treevalc.c(95) : error C2143: syntax error : missing ';' before 'type'
C:\Users\Deepa\Documents\MATLAB\treevalc.c(97) : error C2143: syntax error : missing ';' before 'type'
C:\Users\Deepa\Documents\MATLAB\treevalc.c(100) : error C2143: syntax error : missing ';' before 'type'
C:\Users\Deepa\Documents\MATLAB\treevalc.c(101) : error C2143: syntax error : missing ';' before 'type'
C:\Users\Deepa\Documents\MATLAB\treevalc.c(102) : error C2143: syntax error : missing ';' before 'type'
C:\Users\Deepa\Documents\MATLAB\treevalc.c(104) : error C2143: syntax error : missing ';' before 'type'
C:\Users\Deepa\Documents\MATLAB\treevalc.c(105) : error C2065: 'n' : undeclared identifier
C:\Users\Deepa\Documents\MATLAB\treevalc.c(105) : error C2065: 'n' : undeclared identifier
C:\Users\Deepa\Documents\MATLAB\treevalc.c(105) : error C2065: 'nsplits' : undeclared identifier
C:\Users\Deepa\Documents\MATLAB\treevalc.c(105) : error C2065: 'n' : undeclared identifier
C:\Users\Deepa\Documents\MATLAB\treevalc.c(106) : error C2065: 'n' : undeclared identifier
C:\Users\Deepa\Documents\MATLAB\treevalc.c(110) : error C2065: 'ncatsplit' : undeclared identifier
C:\Users\Deepa\Documents\MATLAB\treevalc.c(110) : error C2065: 'n' : undeclared identifier
C:\Users\Deepa\Documents\MATLAB\treevalc.c(110) : error C2109: subscript requires array or pointer type
C:\Users\Deepa\Documents\MATLAB\treevalc.c(111) : error C2065: 'catsplit' : undeclared identifier
C:\Users\Deepa\Documents\MATLAB\treevalc.c(111) : error C2065: 'n' : undeclared identifier
C:\Users\Deepa\Documents\MATLAB\treevalc.c(111) : error C2109: subscript requires array or pointer type
C:\Users\Deepa\Documents\MATLAB\treevalc.c(114) : error C2143: syntax error : missing ';' before 'type'
C:\Users\Deepa\Documents\MATLAB\treevalc.c(115) : error C2143: syntax error : missing ';' before 'type'
C:\Users\Deepa\Documents\MATLAB\treevalc.c(119) : error C2143: syntax error : missing ';' before 'type'
C:\Users\Deepa\Documents\MATLAB\treevalc.c(121) : error C2065: 'numdata' : undeclared identifier
C:\Users\Deepa\Documents\MATLAB\treevalc.c(122) : error C2143: syntax error : missing ';' before 'type'
C:\Users\Deepa\Documents\MATLAB\treevalc.c(125) : error C2143: syntax error : missing ';' before 'type'
C:\Users\Deepa\Documents\MATLAB\treevalc.c(126) : error C2065: 'n' : undeclared identifier
C:\Users\Deepa\Documents\MATLAB\treevalc.c(126) : error C2065: 'n' : undeclared identifier
C:\Users\Deepa\Documents\MATLAB\treevalc.c(126) : error C2065: 'numdata' : undeclared identifier
C:\Users\Deepa\Documents\MATLAB\treevalc.c(126) : error C2065: 'n' : undeclared identifier
C:\Users\Deepa\Documents\MATLAB\treevalc.c(127) : error C2065: 'var' : undeclared identifier
C:\Users\Deepa\Documents\MATLAB\treevalc.c(127) : warning C4047: 'function' : 'int *' differs in levels of indirection
from 'int'
I am able to call successfully .cpp file in matlab but getting error while using .c file. I am using windows 10 matlab r2014a.
4 件のコメント
回答 (1 件)
Walter Roberson
2018 年 1 月 10 日
Near line 87 you have executable code before you declare some of your local variables. That is valid C++, and it is valid in later C releases, but it is not valid in the default compilation model of C89.
You will need to do one of the following:
- move those lines to after the initialization; or
- put a {} around that initialization and to the rest of the function, so that the initializations are the first thing within a block; or
- add the -std=c99 compile option; or
- if you are using the GUI to set up the compile, find the place in the GUI to mark that you want C99 or C11.
参考
カテゴリ
Help Center および File Exchange で Introduction to Installation and Licensing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!