Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to convert matlab m file to c code

Status
Not open for further replies.

senthilkumar

Advanced Member level 1
Advanced Member level 1
Joined
Nov 24, 2001
Messages
401
Helped
27
Reputation
54
Reaction score
19
Trophy points
1,298
Location
india
Activity points
3,965
hai,

pls explain

how to convert matlab m file to c code

bye
 

just apply the compiler toolbox. before u compile ur m code into c code, u have to make sure ur matlab is full version, including compiler toolbox..
 

Then some examples :)

Make a C translation and a MEX-file for myfun.m:
mcc -x myfun

Make a C translation and a stand-alone executable for myfun.m:
mcc -m myfun

Make a C++ translation and a stand-alone executable for myfun.m:
mcc -p myfun

Make a C translation and a Simulink S-function for myfun.m
(using dynamically sized inputs and outputs):
mcc -S myfun

Make a C translation and a Simulink S-function for myfun.m
(explicitly calling for one input and two outputs):
mcc -S -u 1 -y 2 myfun

Make a C translation and stand-alone executable for myfun.m. Look for
myfun.m in the directory /files/source, and put the resulting C files and
executable in the directory /files/target:
mcc -m -I /files/source -d /files/target myfun

Make a C translation and a MEX-file for myfun.m. Also translate and include
all M-functions called directly or indirectly by myfun.m. Incorporate the
full text of the original M-files into their corresponding C files as C
comments:
mcc -x -h -A annotation:all myfun

Make a generic C translation of myfun.m:
mcc -t -L C myfun

Make a generic C++ translation of myfun.m:
mcc -t -L Cpp myfun

Make a C MEX wrapper file from myfun1.m and myfun2.m:
mcc -W mex -L C myfun1 myfun2

Make a C translation and a stand-alone executable from myfun1.m and myfun2.m
(using one mcc call):
mcc -m myfun1 myfun2

Make a C translation and a stand-alone executable from myfun1.m and myfun2.m
(by generating each output file with a separate mcc call):
mcc -t -L C myfun1 % yields myfun1.c
mcc -t -L C myfun2 % yields myfun2.c
mcc -W main -L C myfun1 myfun2 % yields myfun1_main.c
mcc -T compile:exe myfun1.c % yields myfun1.o
mcc -T compile:exe myfun2.c % yields myfun2.o
mcc -T compile:exe myfun1_main.c % yields myfun1_main.o
mcc -T link:exe myfun1.o myfun2.o myfun1_main.o

Note: on PCs, filenames ending with .o above would actually end with .obj.
.
 

Dear Dspnut and fellow posters,

the solution you are referring produces C code with many library calls to PROPRIETARY libraries (e.g. of a MatLab toolbox). May a good solution (means portable) is a clean-cut translation of the M expressions to corresponding C expressions. It would also be more intuitive for the interested uesr to reuse the code as he likes and not in some EXE form or within Matlab.

Example: this could be done by writing an M-to-C translator in YACC and FLEX, using the attributed M and C grammars.

Please respond if anyone has a ready solution to this (pure m-to-c translation). Or some nice ideas.

thanks

the_penetrator©
 

Matcom can do it.
 

eman said:
Matcom can do it.
Sory, but is that product any different to the matlab compiler itself?
They have the same name, the commands in the example figures are the same as those used in matlab (mcc ...)
And for downloadind the demo version you have to be a member.
 

MATCOM is a products from MATHTOOLS many years ago and the company is taken over by Mathworks.

All new MATLAB compilers are the successor from MATCOM under MATLAB now.

The last MATCOM called Visual MATCOM is very nice...

eYe
 

Hi all,

I have tried using mcc,
"mcc -x myfun"
"mcc -m myfun"

But I always get the error
"??? Error: File "myfun" is a script M-file and cannot be compiled with the current Compiler.
Error in ==> D:\win32\MATLAB\toolbox\compiler\mcc.dll"

The content of my "myfun.m" is
"close all;
clear all;
clc;
disp('testing');"

Can anyone tell me what to do?

mesfet
 

mesfet said:
"??? Error: File "myfun" is a script M-file and cannot be compiled with the current Compiler.
Error in ==> D:\win32\MATLAB\toolbox\compiler\mcc.dll"
...
Can anyone tell me what to do?
mesfet
You (and the manual explains that) cannot convert script m files to c. In order to the conversion to work, your m files must contain only functions.
 

Convert it to functions, always.


And yes it convert to propietary function but all the documentation of libraries are in the API reference and are easy to use and understand

nebisman
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top