convert MATLAB to C using emlc function

My final year project involves converting matlab .m file into C. Upon using the emlc function as many suggested, this error popped out:
??? This text contains non-empty top-level expressions. It appears to be a script.
from this command line: emlc -c lnorm
I tried to read through the online help but I can't seem to understand. Are there any steps that I've missed out?
Please help. Many thanks.

回答 (1 件)

Walter Roberson
Walter Roberson 2011 年 3 月 10 日

0 投票

The file you converted: does the first non-empty non-comment line of it start with the word 'function' ? If not then Matlab considers it a "script". elmc is not able to handle scripts (though 2010b might have added that facility, perhaps, in parallel with the Matlab Compiler having had that ability added.)

6 件のコメント

highstreets
highstreets 2011 年 3 月 10 日
Nope, the first line of my .m file doesn't start with "function". It only starts with initializing some parameters that I'm going to use.
Does it mean I have to convert my whole script into a function just so I can use emlc function. If not, what are the other ways that I can try out?
Many thanks.
Ben Tordoff
Ben Tordoff 2011 年 3 月 10 日
"Converting" the whole script probably involves putting the line
function myFunction()
at the top. It's got to be worth a try ;-)
Walter Roberson
Walter Roberson 2011 年 3 月 10 日
In this case,
function lnorm
should do.
highstreets
highstreets 2011 年 3 月 10 日
Thanks guys for the prompt reply! emlc function managed to run through my whole matlab script but failed to generate a C code. There is a build error as below:
12 'cmd' is not recognized as an internal or external command,
13 operable program or batch file.
14 gmake: *** [lnorm.mexw32] Error 1
Does it have something to do with my computer settings?
Many thanks.
Walter Roberson
Walter Roberson 2011 年 3 月 10 日
Hmmm.... I wonder if it needs cmd.exe ?? 'cmd' should be the normal command shell, I would think.
I don't have a Windows machine available to test this out on.
Kaustubha Govind
Kaustubha Govind 2011 年 3 月 11 日
It looks like the C code is being generated, but it failing to compile the code because it chokes on a call to gmake. MATLAB executes gmake by calling into the system shell - in this case, cmd.exe. It finds cmd.exe by looking on the system path. Either your Path or SystemRoot environment variables are corrupted. Try this from MATLAB command prompt:
>> !echo %SystemRoot%
>> !echo %Path%
Now, look for cmd.exe on your system and verify that the parent directory is present on the system Path.

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

カテゴリ

ヘルプ センター および File ExchangeIntroduction to Installation and Licensing についてさらに検索

質問済み:

2011 年 3 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by