<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158966</link>
    <title>MATLAB Central Newsreader - Converting Matlab .m file into C code</title>
    <description>Feed for thread: Converting Matlab .m file into C code</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Thu, 08 Nov 2007 04:53:00 -0500</pubDate>
      <title>Converting Matlab .m file into C code</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158966#400301</link>
      <author>Ashraf Awad</author>
      <description>Is there a chance, in Matlab, to convert &quot;.m file&quot; into &lt;br&gt;
a &quot;c code&quot;, to run it separately from Matlab?. How, if it &lt;br&gt;
is possible?&lt;br&gt;
Thank you&lt;br&gt;
Ashraf awad&lt;br&gt;
&amp;nbsp;</description>
    </item>
    <item>
      <pubDate>Thu, 02 Oct 2008 19:49:02 -0400</pubDate>
      <title>Re: Converting Matlab .m file into C code</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158966#603453</link>
      <author>Becky J.</author>
      <description>&quot;Ashraf Awad&quot; &amp;lt;a_awad@hotmail.com&amp;gt; wrote in message &amp;lt;fgu4nb$6fe$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Is there a chance, in Matlab, to convert &quot;.m file&quot; into &lt;br&gt;
&amp;gt; a &quot;c code&quot;, to run it separately from Matlab?. How, if it &lt;br&gt;
&amp;gt; is possible?&lt;br&gt;
&amp;gt; Thank you&lt;br&gt;
&amp;gt; Ashraf awad&lt;br&gt;
&amp;gt;  &lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Did you find an answer to this question? </description>
    </item>
    <item>
      <pubDate>Thu, 02 Oct 2008 21:54:15 -0400</pubDate>
      <title>Re: Converting Matlab .m file into C code</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158966#603476</link>
      <author>Walter Roberson</author>
      <description>Becky J. wrote:&lt;br&gt;
&amp;gt; &quot;Ashraf Awad&quot; &amp;lt;a_awad@hotmail.com&amp;gt; wrote in message &amp;lt;fgu4nb$6fe$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt;&amp;gt; Is there a chance, in Matlab, to convert &quot;.m file&quot; into &lt;br&gt;
&amp;gt;&amp;gt; a &quot;c code&quot;, to run it separately from Matlab?. How, if it &lt;br&gt;
&amp;gt;&amp;gt; is possible?&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;gt; Did you find an answer to this question? &lt;br&gt;
&lt;br&gt;
It is not possible except with older (unsupported) versions of Matlab with&lt;br&gt;
the older (unsupported) matlab compiler. Current (supported) Matlab versions&lt;br&gt;
compile to threaded interpreted code, not to C or C++.&lt;br&gt;
&lt;br&gt;
I should expand a bit and mention that a couple of Matlab tools such as the&lt;br&gt;
Real Time Workshop, and Embedded Matlab, *do* generate C, for the functions&lt;br&gt;
they support.</description>
    </item>
    <item>
      <pubDate>Thu, 02 Oct 2008 23:11:02 -0400</pubDate>
      <title>Re: Converting Matlab .m file into C code</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158966#603487</link>
      <author>Judy </author>
      <description>I thought that the MATLAB Compiler converts the m code into C.. So instead it is the libraries that are being shared and C can read the m code in this way?&lt;br&gt;
&lt;br&gt;
In other words, we would still need to use matlab as an interim step as the compiler to get to C..?</description>
    </item>
    <item>
      <pubDate>Fri, 03 Oct 2008 00:36:26 -0400</pubDate>
      <title>Re: Converting Matlab .m file into C code</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158966#603491</link>
      <author>Walter Roberson</author>
      <description>Judy wrote:&lt;br&gt;
&amp;gt; I thought that the MATLAB Compiler converts the m code into C..&lt;br&gt;
&lt;br&gt;
Not any more.&lt;br&gt;
&lt;br&gt;
&amp;gt; So instead it is the libraries that are being shared and C can read the m code in&lt;br&gt;
&amp;gt; this way?&lt;br&gt;
&lt;br&gt;
&amp;gt; In other words, we would still need to use matlab as an interim step as the&lt;br&gt;
&amp;gt; compiler to get to C..?&lt;br&gt;
&lt;br&gt;
Unless you are using one of the Builders, or Embedded Matlab, or the Real Time&lt;br&gt;
Workshop, then the modern versions of the matlab compilers transform each .m file&lt;br&gt;
into encrypted binary data files. The matlab compiler &quot;executable&quot; is a program that&lt;br&gt;
knows how to decrypt the binary data files and step through the resulting&lt;br&gt;
structured binary data, each bit of which is interpreted as either control logic&lt;br&gt;
or calls to the matlab libraries. No C is generated or compiled (not unless &lt;br&gt;
you had some mex in the mix.)&lt;br&gt;
&lt;br&gt;
With the generated files being binary data files, they are portable to different&lt;br&gt;
operating systems: you just have to replace the interpreter portion and use the same&lt;br&gt;
encrypted binary data files, instead of having to generate code for each different&lt;br&gt;
operating system and each different architecture that you want to run on.</description>
    </item>
    <item>
      <pubDate>Tue, 07 Oct 2008 21:22:01 -0400</pubDate>
      <title>Re: Converting Matlab .m file into C code</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158966#604227</link>
      <author>Alamzeb </author>
      <description>Hey Walter,&lt;br&gt;
&lt;br&gt;
In response to your comment:&lt;br&gt;
&amp;gt;It is not possible except with older (unsupported) &amp;gt;versions of Matlab with&lt;br&gt;
&amp;gt;the older (unsupported) matlab compiler. Current &lt;br&gt;
&amp;gt;(supported) Matlab versions&lt;br&gt;
&amp;gt;compile to threaded interpreted code, not to C or C++.&lt;br&gt;
&lt;br&gt;
Can I get the older matlab version somehow? and would it generate c code for guide commands as well?</description>
    </item>
    <item>
      <pubDate>Wed, 08 Oct 2008 08:03:05 -0400</pubDate>
      <title>Re: Converting Matlab .m file into C code</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158966#604260</link>
      <author>Arnaud Miege</author>
      <description>&lt;br&gt;
&quot;Alamzeb &quot; &amp;lt;alamzeb.khan@nov.com&amp;gt; wrote in message &lt;br&gt;
news:gcgjtp$k1e$1@fred.mathworks.com...&lt;br&gt;
&amp;gt; Hey Walter,&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; In response to your comment:&lt;br&gt;
&amp;gt;&amp;gt;It is not possible except with older (unsupported) &amp;gt;versions of Matlab &lt;br&gt;
&amp;gt;&amp;gt;with&lt;br&gt;
&amp;gt;&amp;gt;the older (unsupported) matlab compiler. Current&lt;br&gt;
&amp;gt;&amp;gt;(supported) Matlab versions&lt;br&gt;
&amp;gt;&amp;gt;compile to threaded interpreted code, not to C or C++.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; Can I get the older matlab version somehow? and would it generate c code &lt;br&gt;
&amp;gt; for guide commands as well?&lt;br&gt;
&amp;gt;&lt;br&gt;
&lt;br&gt;
The MATLAB  Compiler is used for deployment, i.e. sharing MATLAB &lt;br&gt;
applications with people who do not have MATLAB installed, but not for &lt;br&gt;
generating C code. If you want to generate C code from MATLAB for running in &lt;br&gt;
real-time on an embedded microprocessor, then you need to use Embedded &lt;br&gt;
MATLAB:&lt;br&gt;
&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/products/featured/embeddedmatlab/&quot;&gt;http://www.mathworks.com/products/featured/embeddedmatlab/&lt;/a&gt;&lt;br&gt;
&lt;a href=&quot;http://www.mathworks.com/access/helpdesk/help/toolbox/eml/&quot;&gt;http://www.mathworks.com/access/helpdesk/help/toolbox/eml/&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
Note that only a subset of the MATLAB language is supported by Embedded &lt;br&gt;
MATLAB for code generation and that it requires Real-Time Workshop &lt;br&gt;
(&lt;a href=&quot;http://www.mathworks.com/products/rtw/).&quot;&gt;http://www.mathworks.com/products/rtw/).&lt;/a&gt;&lt;br&gt;
&lt;br&gt;
Hope this helps,&lt;br&gt;
&lt;br&gt;
Arnaud </description>
    </item>
    <item>
      <pubDate>Wed, 08 Oct 2008 16:16:16 -0400</pubDate>
      <title>Re: Converting Matlab .m file into C code</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158966#604276</link>
      <author>Walter Roberson</author>
      <description>Alamzeb wrote:&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;gt; In response to your comment:&lt;br&gt;
&amp;gt;&amp;gt; It is not possible except with older (unsupported) &amp;gt;versions of Matlab with&lt;br&gt;
&amp;gt;&amp;gt; the older (unsupported) matlab compiler. Current &lt;br&gt;
&amp;gt;&amp;gt; (supported) Matlab versions&lt;br&gt;
&amp;gt;&amp;gt; compile to threaded interpreted code, not to C or C++.&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;gt; Can I get the older matlab version somehow? and would it generate c code for guide commands as well?&lt;br&gt;
&lt;br&gt;
I think it would be possible to get ahold of the media through some channel or other&lt;br&gt;
(possibly of suspect legality), but I don't think Mathworks would issue a license for you.&lt;br&gt;
&lt;br&gt;
The only possible exception I can think of, is if you were to literally buy an entire &lt;br&gt;
company that happened to have a legal license for an appropriate version: then it would &lt;br&gt;
just be a matter of getting a new key for your license. Licenses are not transferable&lt;br&gt;
except (if I recall correctly) when the entire company is purchased.&lt;br&gt;
&lt;br&gt;
Recall that if you did get an appropriate old version, then it would not support a number&lt;br&gt;
of the newer features. To the extent that it supported GUIDE, it would do so only to the&lt;br&gt;
limit of the constructs that GUIDE generates that were supported in that old release.</description>
    </item>
    <item>
      <pubDate>Thu, 09 Oct 2008 13:53:13 -0400</pubDate>
      <title>Re: Converting Matlab .m file into C code</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158966#604367</link>
      <author>Paul Mennen</author>
      <description>&quot;Alamzeb &quot; wrote&lt;br&gt;
&amp;nbsp;&lt;br&gt;
&amp;gt; Can I get the older matlab version somehow? and would&lt;br&gt;
&amp;gt; it generate c code for guide commands as well?&lt;br&gt;
&lt;br&gt;
I usually use Matlab ver 6.1 for that reason.&lt;br&gt;
(I like the older compiler far better). I've&lt;br&gt;
compiled many GUIs with it, although I don't use&lt;br&gt;
guide so I can't report directly on that. I'm&lt;br&gt;
pretty sure it would work on guide applications&lt;br&gt;
though, but you would have to use the version of&lt;br&gt;
guide that came with ver 6 matlab.&lt;br&gt;
&lt;br&gt;
I don't think there is any way to legally get&lt;br&gt;
this software anymore, since the Mathworks no&lt;br&gt;
longer sells it.&lt;br&gt;
&lt;br&gt;
~Paul</description>
    </item>
    <item>
      <pubDate>Thu, 09 Oct 2008 13:53:22 -0400</pubDate>
      <title>Re: Converting Matlab .m file into C code</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158966#604419</link>
      <author>John reilly</author>
      <description>For those of you who want to convert MATLAB to C, the fundamental question is:  Why?  What do you hope to gain?&lt;br&gt;
&lt;br&gt;
If you answer that, someone can tell you the best way to proceed.&lt;br&gt;
&lt;br&gt;
Once upon a midnight dreary, someone posted in this forum a link to a tool that converts MATLAB to C.  It is probably very expensive.&lt;br&gt;
&lt;br&gt;
The MATLAB Compiler/Builder tools will generate a DLL that you can call from C/C++/C#/whatever.  You can write your application, and distribute it with the DLL and the MATLAB Compiler Runtime (MCR) (170+MB) so that your users can run your app without needing MATLAB.  The compiler can also generate an exe from your script, including a GUIDE script.&lt;br&gt;
&lt;br&gt;
You can implement your MATLAB in a Simulink model (say an embedded MATLAB function block, which has some restrictions) and RealTime Workshop will generate C.&lt;br&gt;
&lt;br&gt;
Walter covered all this, I know.  But he could answer you a lot better if you'd tell him *WHY* you want to convert to C.&lt;br&gt;
&lt;br&gt;
reilly.</description>
    </item>
    <item>
      <pubDate>Thu, 09 Oct 2008 17:54:13 -0400</pubDate>
      <title>Re: Converting Matlab .m file into C code</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158966#604497</link>
      <author>Walter Roberson</author>
      <description>John Reilly wrote:&lt;br&gt;
&amp;gt; For those of you who want to convert MATLAB to C, the fundamental question is:  Why?&lt;br&gt;
&amp;gt; What do you hope to gain?&lt;br&gt;
&lt;br&gt;
Experience suggests that when people ask for this, they are asking for one of three things:&lt;br&gt;
&lt;br&gt;
A) A deployment tool similar in effect to the Matlab compiler, but without the cost associated&lt;br&gt;
with the official Matlab compiler; Or&lt;br&gt;
&lt;br&gt;
B) A deployment tool similar in effect to the Matlab compiler, but which produces *much* smaller&lt;br&gt;
packages by only including the parts of Matlab that are &quot;actually used&quot; for the program;&lt;br&gt;
said package should include a magic version of BLAS (and similar libraries) that is&lt;br&gt;
simultaneously optimized for all possible target processors so the delivered executable will&lt;br&gt;
&quot;just work&quot; (but of course, only the portions of those libraries that will actually be called&lt;br&gt;
upon should be included); Or&lt;br&gt;
&lt;br&gt;
C) A tool that will speed up their code by a factor of at least 20 (worst case), with 80 to 100 times&lt;br&gt;
speedup -expected-, because &quot;everyone knows&quot; that Matlab is much slower than C.&lt;br&gt;
&lt;br&gt;
&amp;gt; Walter covered all this, I know.  But he could answer you a lot better if you'd tell him&lt;br&gt;
&amp;gt; *WHY* you want to convert to C.&lt;br&gt;
&lt;br&gt;
Unfortunately Walter has no &quot;better&quot; answer to any of the above situations than he has&lt;br&gt;
already posted. Walter is a Mathworks customer, not a Mathworks employee, and Mathworks&lt;br&gt;
typically doesn't tell him much more than &quot;This will be fixed in a future release&quot;.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;</description>
    </item>
    <item>
      <pubDate>Thu, 16 Oct 2008 13:05:04 -0400</pubDate>
      <title>Re: Converting Matlab .m file into C code</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158966#605675</link>
      <author>amir </author>
      <description>&quot;John Reilly&quot; &amp;lt;jrhokie1.nospam@yahoo.com&amp;gt; wrote in message &amp;lt;gcl2ci$oq$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; For those of you who want to convert MATLAB to C, the fundamental question is:  Why?  What do you hope to gain?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; If you answer that, someone can tell you the best way to proceed.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Once upon a midnight dreary, someone posted in this forum a link to a tool that converts MATLAB to C.  It is probably very expensive.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; The MATLAB Compiler/Builder tools will generate a DLL that you can call from C/C++/C#/whatever.  You can write your application, and distribute it with the DLL and the MATLAB Compiler Runtime (MCR) (170+MB) so that your users can run your app without needing MATLAB.  The compiler can also generate an exe from your script, including a GUIDE script.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; You can implement your MATLAB in a Simulink model (say an embedded MATLAB function block, which has some restrictions) and RealTime Workshop will generate C.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Walter covered all this, I know.  But he could answer you a lot better if you'd tell him *WHY* you want to convert to C.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; reilly.&lt;br&gt;
Hi Reilly,&lt;br&gt;
&lt;br&gt;
i need to make a exe or any other form of my m-file which could be run inside my Compaq visual Fortran6.6. is it possible to make it with Matlab7.6 ?&lt;br&gt;
because i have tried a lot, but it seems CVF is not supported by your MATLAB version 2008a. &lt;br&gt;
Amir</description>
    </item>
    <item>
      <pubDate>Fri, 31 Oct 2008 15:45:57 -0400</pubDate>
      <title>Re: Converting Matlab .m file into C code</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158966#608374</link>
      <author>rustic.drive@gmail.com</author>
      <description>On Oct 9, 1:54=A0pm, Walter Roberson &amp;lt;rober...@hushmail.com&amp;gt; wrote:&lt;br&gt;
&amp;gt; B) A deployment tool similar in effect to theMatlabcompiler, but which pr=&lt;br&gt;
oduces *much* smaller&lt;br&gt;
&amp;gt; packages by only including the parts ofMatlabthat are &quot;actually used&quot; for=&lt;br&gt;
&amp;nbsp;the program;&lt;br&gt;
&amp;gt; said package should include a magic version of BLAS (and similar librarie=&lt;br&gt;
s) that is&lt;br&gt;
&amp;gt; simultaneously optimized for all possible target processors so the delive=&lt;br&gt;
red executable will&lt;br&gt;
&amp;gt; &quot;just work&quot; (but of course, only the portions of those libraries that wil=&lt;br&gt;
l actually be called&lt;br&gt;
&amp;gt; upon should be included); Or&lt;br&gt;
&lt;br&gt;
&amp;gt; C) A tool that will speed up their code by a factor of at least 20 (worst=&lt;br&gt;
&amp;nbsp;case), with 80 to 100 times&lt;br&gt;
&amp;gt; speedup -expected-, because &quot;everyone knows&quot; thatMatlabis much slower tha=&lt;br&gt;
nC.&lt;br&gt;
&amp;gt;&lt;br&gt;
&amp;gt; &amp;gt; Walter covered all this, I know. =A0But he could answer you a lot bette=&lt;br&gt;
r if you'd tell him&lt;br&gt;
&amp;gt; &amp;gt; *WHY* you want to convert toC.&lt;br&gt;
&lt;br&gt;
Walter, thanks for your insight into Matlab compiler and Embedded&lt;br&gt;
Matlab.&lt;br&gt;
I am looking to convert some Matlab code into C. Reason : I want my&lt;br&gt;
code to run as fast as possible. It will not be a real time app and&lt;br&gt;
will sit on a PC. But execution time is important.&lt;br&gt;
I have been researching this and spoke to Mathworks support recently.&lt;br&gt;
&lt;br&gt;
This is what I learnt about Embedded Matlab:&lt;br&gt;
-Will need to buy Real Time Workshop and Simulink ($ 7500+3000)&lt;br&gt;
- Embedded Matlab (emlc) is limited&lt;br&gt;
	a. Not all functions can be translated&lt;br&gt;
	b. M code to be written to be compliant with emlc guidelines&lt;br&gt;
	c. Will not be as fast as normal C&lt;br&gt;
	d. &amp;lt;my thought&amp;gt; Unknown issues that may arise from machine generated&lt;br&gt;
code&lt;br&gt;
&lt;br&gt;
The support person seemed to suggest that Matlab compiler might be a&lt;br&gt;
solution that runs faster.&lt;br&gt;
&lt;br&gt;
From your experience,&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1. how reliable is C code generated by matlab&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2. how much of a pain is it to write m code that is Embedded&lt;br&gt;
Matlab compliant&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3. do you know if a Matlab Compiler solution might run faster&lt;br&gt;
than Embedded Matlab generated C&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4. How much faster is Embedded Matlab generated C than normal&lt;br&gt;
Matlab&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5. Do you have any insights on the Parallel computing Toolbox?&lt;br&gt;
&lt;br&gt;
Thank you,&lt;br&gt;
Madhu</description>
    </item>
    <item>
      <pubDate>Tue, 09 Dec 2008 23:41:02 -0500</pubDate>
      <title>Re: Converting Matlab .m file into C code</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/158966#616062</link>
      <author>Mike </author>
      <description>Can some body tel me the reason why the removed C generation from matlab?&lt;br&gt;
&lt;br&gt;
I have always used matlab for signal and image process algorthim devlopment not running the actually program live. Once a working algorithm has been found I concerted to much faster compliers.&lt;br&gt;
&lt;br&gt;
Because matlab is so slow it has to be run independly on a seperate C application to have a chance of running machine vision systems. &lt;br&gt;
Now, I have no problem operating scilab for my work and it costs nothing and the only advatage matlab had was the abilty to generate C code. Matlab has effectly just removed its advantage of an automated method of going from protoype code to useful &quot;real time&quot; use. &lt;br&gt;
I'd now have to do it manually so why the hell would you pay thousands of dollars for a liceance when it now requires the same work as the opensource application?&lt;br&gt;
&lt;br&gt;
Do they actually think it is acceptable to need to install matlab componets on customers equipment? and have the application run far slower?</description>
    </item>
  </channel>
</rss>

