Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

how to convert matlab m file to c code

Status
Not open for further replies.

senthilkumar

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,969
hai,

pls explain

how to convert matlab m file to c code

bye
 

leong

Newbie level 5
Joined
Jan 16, 2003
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
72
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..
 

Dspnut

Full Member level 2
Joined
Jul 18, 2002
Messages
141
Helped
10
Reputation
18
Reaction score
5
Trophy points
1,298
Activity points
1,267
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.
.
 

the_penetrator

Full Member level 5
Joined
Jun 22, 2001
Messages
297
Helped
10
Reputation
20
Reaction score
5
Trophy points
1,298
Activity points
2,775
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©
 

eman

Member level 1
Joined
Jun 23, 2001
Messages
33
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
165
Matcom can do it.
 

pardal

Member level 5
Joined
Dec 29, 2001
Messages
81
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,288
Activity points
587
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.
 

eYe

Member level 4
Joined
Aug 12, 2001
Messages
79
Helped
5
Reputation
10
Reaction score
4
Trophy points
1,288
Activity points
607
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
 

mesfet

Full Member level 2
Joined
Jan 4, 2002
Messages
131
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Activity points
1,111
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
 

pardal

Member level 5
Joined
Dec 29, 2001
Messages
81
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,288
Activity points
587
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.
 

nebisman

Full Member level 4
Joined
Apr 13, 2002
Messages
226
Helped
10
Reputation
22
Reaction score
9
Trophy points
1,298
Activity points
1,849
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.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top