f



Matlab code to C-code

If I want to generate C-code from m-file not specifically 
for embedded target, which tool can I use?  As of I know 
emlc converts embedded MATALAB code to C-code.  Does the 
Real-Time Workshop uses emlc? Please any one tell me how 
can I convert my m-file (not only embedded m-file) to C-
code.
0
4/22/2008 6:56:02 AM
comp.soft-sys.matlab 211266 articles. 22 followers. lunamoonmoon (257) is leader. Post Follow

7 Replies
1140 Views

Similar Articles

[PageSpeed] 11

Hi Naveen,

i don't think you can do this.  if you could, TMW would be
giving away the store!  you can, however, use the MATLAB
Compiler to generate a DLL that you can call from C.  MCC
will generate a little stub that you call.  That stub will
call into the MCR (MATLAB Component Runtime) to execute your
m-script.  With that, you can do most anything MATLAB.  Your
client will be required to install the svelte MCR (+/- 175
MB) if it doesn't have MATLAB installed.

reilly.


"Naveen " <naveen.onkarappa@hcl.in> wrote in message
<fuk262$ki9$1@fred.mathworks.com>...
> If I want to generate C-code from m-file not specifically 
> for embedded target, which tool can I use?  As of I know 
> emlc converts embedded MATALAB code to C-code.  Does the 
> Real-Time Workshop uses emlc? Please any one tell me how 
> can I convert my m-file (not only embedded m-file) to C-
> code.

0
4/22/2008 2:44:03 PM
"Naveen " <naveen.onkarappa@hcl.in> wrote in message 
news:fuk262$ki9$1@fred.mathworks.com...
> If I want to generate C-code from m-file not specifically
> for embedded target, which tool can I use?  As of I know
> emlc converts embedded MATALAB code to C-code.  Does the
> Real-Time Workshop uses emlc? Please any one tell me how
> can I convert my m-file (not only embedded m-file) to C-
> code.

Hi,

Embedded MATLAB does just that, but you are right in the sense that it's 
generally used for running in real-time on an embedded target (hence the 
name). The emlc command allows you to generate C code from M file at the 
MATLAB command line (see 
http://www.mathworks.com/access/helpdesk/help/toolbox/rtw/ref/emlc.html and 
http://www.mathworks.com/access/helpdesk/help/toolbox/rtw/ug/bq8j0_1.html 
for more details). As the purpose is to run in real-time, only a subset of 
the MATLAB language is supported (see 
http://www.mathworks.com/access/helpdesk/help/toolbox/eml/ug/bq1h2z5-1.html 
for more details). That subset is however growing with each release. It does 
require Real-Time Workshop, which in turns requires Simulink. I'm curious: 
why do you want to generate C code from your M code if it's not to run in 
real-time?

Hope this helps,

Arnaud


0
4/22/2008 4:15:32 PM
"John Reilly" <jrhokie1.nospam@yahoo.com> wrote in message 
<fuktjj$p5m$1@fred.mathworks.com>...
> Hi Naveen,
> 
> i don't think you can do this.  if you could, TMW would 
be
> giving away the store!  you can, however, use the MATLAB
> Compiler to generate a DLL that you can call from C.  MCC
> will generate a little stub that you call.  That stub 
will
> call into the MCR (MATLAB Component Runtime) to execute 
your
> m-script.  With that, you can do most anything MATLAB.  
Your
> client will be required to install the svelte MCR (+/- 
175
> MB) if it doesn't have MATLAB installed.
> 
> reilly.
> 
> 
> "Naveen " <naveen.onkarappa@hcl.in> wrote in message
> <fuk262$ki9$1@fred.mathworks.com>...
> > If I want to generate C-code from m-file not 
specifically 
> > for embedded target, which tool can I use?  As of I 
know 
> > emlc converts embedded MATALAB code to C-code.  Does 
the 
> > Real-Time Workshop uses emlc? Please any one tell me 
how 
> > can I convert my m-file (not only embedded m-file) to 
C-
> > code.
> 


Thanks Reilly,
Instead of generating dll from m-file using mcc, can't I 
generate C-code?
0
4/23/2008 7:32:02 AM
"Arnaud Miege" <arnaud.miege@mathworks.co.uk> wrote in 
message <ful2v5$j9r$1@fred.mathworks.com>...
> 
> "Naveen " <naveen.onkarappa@hcl.in> wrote in message 
> news:fuk262$ki9$1@fred.mathworks.com...
> > If I want to generate C-code from m-file not 
specifically
> > for embedded target, which tool can I use?  As of I 
know
> > emlc converts embedded MATALAB code to C-code.  Does 
the
> > Real-Time Workshop uses emlc? Please any one tell me 
how
> > can I convert my m-file (not only embedded m-file) to 
C-
> > code.
> 
> Hi,
> 
> Embedded MATLAB does just that, but you are right in the 
sense that it's 
> generally used for running in real-time on an embedded 
target (hence the 
> name). The emlc command allows you to generate C code 
from M file at the 
> MATLAB command line (see 
> 
http://www.mathworks.com/access/helpdesk/help/toolbox/rtw/r
ef/emlc.html and 
> 
http://www.mathworks.com/access/helpdesk/help/toolbox/rtw/u
g/bq8j0_1.html 
> for more details). As the purpose is to run in real-
time, only a subset of 
> the MATLAB language is supported (see 
> 
http://www.mathworks.com/access/helpdesk/help/toolbox/eml/u
g/bq1h2z5-1.html 
> for more details). That subset is however growing with 
each release. It does 
> require Real-Time Workshop, which in turns requires 
Simulink. I'm curious: 
> why do you want to generate C code from your M code if 
it's not to run in 
> real-time?
> 
> Hope this helps,
> 
> Arnaud
> 
> 


Thanks Arnaud,
I just wanted to generate C-code from the m-file and run 
it in VC++.  And importantly my code contains other than 
embedded matlab inbuilt functions for that I cannot use 
emlc.  Still I am confused whether can I generate C-code 
for general m-file by selecting target as grt_tlc instead 
of ert_XXX... in RTW.

-Naveen 
0
4/23/2008 7:43:02 AM
"Naveen " <naveen.onkarappa@hcl.in> wrote in message <fumpa6
$gqf$1@fred.mathworks.com>...
> "Arnaud Miege" <arnaud.miege@mathworks.co.uk> wrote in 
> message <ful2v5$j9r$1@fred.mathworks.com>...
> > 
> > "Naveen " <naveen.onkarappa@hcl.in> wrote in message 
> > news:fuk262$ki9$1@fred.mathworks.com...
> > > If I want to generate C-code from m-file not 
> specifically
> > > for embedded target, which tool can I use?  As of I 
> know
> > > emlc converts embedded MATALAB code to C-code.  Does 
> the
> > > Real-Time Workshop uses emlc? Please any one tell me 
> how
> > > can I convert my m-file (not only embedded m-file) to 
> C-
> > > code.
> > 
> > Hi,
> > 
> > Embedded MATLAB does just that, but you are right in 
the 
> sense that it's 
> > generally used for running in real-time on an embedded 
> target (hence the 
> > name). The emlc command allows you to generate C code 
> from M file at the 
> > MATLAB command line (see 
> > 
> 
http://www.mathworks.com/access/helpdesk/help/toolbox/rtw/r
> ef/emlc.html and 
> > 
> 
http://www.mathworks.com/access/helpdesk/help/toolbox/rtw/u
> g/bq8j0_1.html 
> > for more details). As the purpose is to run in real-
> time, only a subset of 
> > the MATLAB language is supported (see 
> > 
> 
http://www.mathworks.com/access/helpdesk/help/toolbox/eml/u
> g/bq1h2z5-1.html 
> > for more details). That subset is however growing with 
> each release. It does 
> > require Real-Time Workshop, which in turns requires 
> Simulink. I'm curious: 
> > why do you want to generate C code from your M code if 
> it's not to run in 
> > real-time?
> > 
> > Hope this helps,
> > 
> > Arnaud
> > 
> > 
> 
> 
> Thanks Arnaud,
> I just wanted to generate C-code from the m-file and run 
> it in VC++.  And importantly my code contains other than 
> embedded matlab inbuilt functions for that I cannot use 
> emlc.  Still I am confused whether can I generate C-code 
> for general m-file by selecting target as grt_tlc instead 
> of ert_XXX... in RTW.
> 
> -Naveen 

Hi Naveen,
older versions of MCC - up to Matlab R13, but may be even 
older - used to do just what you're looking for.
TMW have then changed totally the functionality: MCC now 
creates deployable(TMW)/deplorable(critics) packages, while 
Embedded Matlab generates source code.
In theory you could try to get hold of an old Matlab 
release and use that to generate code, provided your m-file 
is compatible.
Riccardo


0
nothx (288)
4/23/2008 8:23:03 AM
>
> Thanks Arnaud,
> I just wanted to generate C-code from the m-file and run
> it in VC++.  And importantly my code contains other than
> embedded matlab inbuilt functions for that I cannot use
> emlc.  Still I am confused whether can I generate C-code
> for general m-file by selecting target as grt_tlc instead
> of ert_XXX... in RTW.
>
> -Naveen

Embedded MATLAB is the only way to generate C code  from M code for what you 
want to be doing, whether this is from MATLAB itself or from an Embedded 
MATLAB block within a Simulink. In both cases, you will need Real-Time 
Workshop and Simulink. However, if your M code 9and it can be a general M 
file) utilizes functions that are not part of subset of the MATLAB language 
supported by Embedded MATLAB as you suggest (if I understand correctly), you 
will not be able to generate C code from it, whether using the GRT or ERT 
target (which by the way is only available with Real-Time Workshop Embedded 
Coder). As Riccardo suggests, you can try using the old MATLAB compiler 
(prior to R13), but this had a lot of limitations.

Hope this helps,

Arnaud 


0
4/23/2008 8:15:33 PM
"Arnaud Miege" <arnaud.miege@mathworks.co.uk> wrote in 
message <fuo5d6$orh$1@fred.mathworks.com>...
> 
> >
> > Thanks Arnaud,
> > I just wanted to generate C-code from the m-file and 
run
> > it in VC++.  And importantly my code contains other 
than
> > embedded matlab inbuilt functions for that I cannot use
> > emlc.  Still I am confused whether can I generate C-
code
> > for general m-file by selecting target as grt_tlc 
instead
> > of ert_XXX... in RTW.
> >
> > -Naveen
> 
> Embedded MATLAB is the only way to generate C code  from 
M code for what you 
> want to be doing, whether this is from MATLAB itself or 
from an Embedded 
> MATLAB block within a Simulink. In both cases, you will 
need Real-Time 
> Workshop and Simulink. However, if your M code 9and it 
can be a general M 
> file) utilizes functions that are not part of subset of 
the MATLAB language 
> supported by Embedded MATLAB as you suggest (if I 
understand correctly), you 
> will not be able to generate C code from it, whether 
using the GRT or ERT 
> target (which by the way is only available with Real-
Time Workshop Embedded 
> Coder). As Riccardo suggests, you can try using the old 
MATLAB compiler 
> (prior to R13), but this had a lot of limitations.
> 
> Hope this helps,
> 
> Arnaud 
> 
> 


Many thanks Arnaud and Riccardo.  I try out mcc in old 
versions of MATLAB.
0
4/24/2008 2:15:06 PM
Reply: