From: Walter Roberson on
James Tursa wrote:
> Walter Roberson <roberson(a)hushmail.com> wrote in message
> <iy2Yn.4543$KT3.4436(a)newsfe13.iad>...
>> shahnaz fatima wrote:
>> > hello everyone here.
>> > > i want to know is it possible to convert .mex to .m file?
>> > > waiting for reply
>>
>> Yes, it is. .mex files use a finite deterministic instruction set

> I don't know what to make of this reply, Walter. It almost sounds like
> you are serious.

Yup. The OP asked if it could be done, and the previous responses that
said "No" were incorrect because it *can* be done. But as you quite
correctly point out, the doing of it is very likely not worth the trouble.

> In addition to just the mex routine itself, you would
> also have to do the same thing with all functional dependencies. So you
> would have to "decompile" all of the compiled MATLAB intrinsic functions
> that it depended on, all of the third party dll stuff it depended on
> (e.g., MSVC libraries), and you would have to provide something to
> replace all of the system service calls, memory management, etc.

In the limited case where calls are only made to the standard C or C++
libraries and to documented Matlab routines, the functions being called
could probably be converted into .m code (possibly with the assistance
of some new additional mex routines to do things like memory management
that Matlab does not provide direct access to.) I think in such a case
one would be able to stop well short of the OS. Efficiency would, of
course, be a secondary consideration.

> Even if you went to all this effort it would likely run several
> orders of magnitude slower.

A number of the old 8-bit arcade games have been implemented as
Javascript in the last couple of years. With modern computers, a
significant problem in the conversion is that the Javascript is too
_fast_ to get the timings right!

It depends, in other words, on what you are comparing against. If you
have a mex file for matlab 4 that ran on a Pentium 4 (say) that is
dead/dying, and you do not have the source anymore, then emulating it
might plausibly turn out to be faster than the original machine,
especially if your emulator is smart enough to use JIT techniques.