Google Answers Logo
View Question
 
Q: converting MATLAB routine to an executable file ( Answered 5 out of 5 stars,   2 Comments )
Question  
Subject: converting MATLAB routine to an executable file
Category: Computers > Programming
Asked by: xman-ga
List Price: $10.00
Posted: 22 Jul 2004 03:24 PDT
Expires: 21 Aug 2004 03:24 PDT
Question ID: 377517
I've found a MATLAB routine which I'd like to run but I don't have
MATLAB.  I need someone convert it into an executable file (or into a
code that can be run in a freely accessable language).

The routine is called "comb_unrank.m" which is found at:
http://www.csit.fsu.edu/~burkardt/m_src/subset/subset.html

NB. I have very limited skills in programming.

Request for Question Clarification by mathtalk-ga on 22 Jul 2004 09:14 PDT
Hi, xman-ga:

I can help with this, but what operating system do you need the
routine to run on?  I'm tempted to assume Windows, but maybe that's
not such a safe assumption these days, with the Mac making a comeback
and Linux charging up strong on the outside.

regards, mathtalk-ga

Clarification of Question by xman-ga on 22 Jul 2004 15:07 PDT
hi mathtalk, I'm using Windows XP.
Also, I am mainly interested in using the routine for M=45, N=6, so
these could be set into the program if it makes it easier (ie. this
goes back to my enumerating lotto numbers question which I think you
commented on).
cheers
Answer  
Subject: Re: converting MATLAB routine to an executable file
Answered By: mathtalk-ga on 23 Jul 2004 04:36 PDT
Rated:5 out of 5 stars
 
Hi, xman-ga:

Yes, I remember the earlier question!

There is an open source mathematical modeling package Octave that has
a pretty good degree of compatibility with Matlab syntax.  I
downloaded version 2.1.50 from one of the mirror sites here (package
octave-forge-windows):

[GNU Octave - SourceForge.net]
http://sourceforge.net/projects/octave

Running under Windows requires first the installation of a
Unix-compatibility layer called Cygwin.  The Cygwin package was
already installed by me on my Windows XP Pro laptop, so I didn't
repeat that step, but see the instructions here:

[Downloading Octave - Latest Release]
http://www.octave.org/download.html

"For Windows, you may follow these directions to install Cygwin and
Octave, or you may use one of the binary packages found at
http://sourceforge.net/projects/octave.

"There is also a FAQ for Octave on Windows systems."

[Cygwin Information and Installation]
http://www.cygwin.com/

[Octave under Windows]
http://octave.sourceforge.net/Octave_Windows.htm

I need to update my Cygwin installation anyway, so I will circle back
and give an account of my adventures doing this in a follow-up post. 
But let me proceed with the account of installing Octave and getting
the .m files you've asked about to run.

I first "uninstalled" my old version of Octave in a brute force
fashion (deleting directories) which I'll not detail.  I then
downloaded (to my XP "desktop") the executable installation program
octave-2.1.50a-inst.exe which you can get from the links above.  (I
had trouble with the North Carolina mirror, and wound up cancelling
that download and pulling from the Minneapolis one.  It very likely
was just an intermittent load problem; you can pick a site "near"
you.)

When you run the install program (double-click after the download to
your desktop is finished), if it finds a previous Cygwin installation
it will prompt you with a warning that the installation is not
designed to run _within_ the Cygwin environment.  That's okay; just
click yes to proceed as you will be running it from Windows (not from
inside a Cygwin terminal, unless you are more adventurous than I am!).

There's a terms of use license to accept, the reknowned GNU/Free
Software Foundation GPL (General Public License).  If you are
philosophically opposed to the open source movement, this package is
not for you!  Otherwise I hope you will find the terms of the license
acceptable, as I did.

After installing Cygwin and Octave (which provides a desktop icon, a
Start Menu entry, and a handy uninstall program in this version), you
are almost set to go.

I downloaded these two "function scripts" from the link you gave:

  comb_unrank.m

  combin2.m

and saved them (basically just as text pages from my Mozilla Firefox
browser) into the directory:

C:\Program Files\GNU Octave 2.1.50\octave_files

The point here is that if you put .m files that define functions in
this directory, then Octave can find them while its running.  You
don't need to do anything special to "compile" them or to let the
Octave environment know where to look.

Now as a first exercise (since I saw that comb_unrank( m, n, rank) was
using it) I tried to invoke combin2(45, 6) from the Octave command
line.  I got this error:

>> combin2(45,6)
parse error near line 48 of file /octave_files/combin2.m

>>>     for ( i = 2 : mn )
                          ^

error: `combin2' undefined near line 13 column 1

Despite the error this was good news in that it shows Octave was
finding the right file.  A quick consultation of the Octave
documentation suggested that the problem was the parentheses around
the "for loop" range.  I edited the source file in Textpad (without
closing Octave) and made a similar change to the other file
(comb_unrank.m also has one for loop).  Because Octave uses the
timestamp on files that define functions to determine if the
definitions need to be re-interpreted, I could then use the corrected
source file without restarting:

>> combin2(45,6)
ans = 8145060
>> comb_unrank(45,6,1)
ans =

        1        2        3        4        5        6

>> comb_unrank(45,6,4072530)
ans =

        5       13       14       25       27       29

So, to summarize, download and install the Cygwin and Octave packages,
download the two .m script files, and make the edits to these "Matlab"
scripts (removing parentheses from one line in each file that starts a
for loop).  Run the Octave program interactively and use the functions
as you wish.

Let me know if you have difficulties, and again, I'll post a follow-up
about installing/reinstalling the Cygwin package (basically a DLL).


regards, mathtalk-ga

P.S.  Thanks, andyt-ga, for the suggestion of using the Matlab
compiler.  The programs SUBSET are also available from links at the
page xman-ga gave in C++ and in Fortran versions, so there are several
options to obtain compiled code.  I found the interactive version to
be fast enough in Octave, but we'll see how well it suits xman-ga.

Clarification of Answer by mathtalk-ga on 24 Jul 2004 07:46 PDT
Hi, xman-ga:

Thanks for the generous comments... the encouragement is appreciated!

I put together these notes for you about Cygwin installation.


[The Cygwin FAQ]
http://www.cygwin.com/faq/

Under: "What version of Cygwin is this, anyway?"

"So, how do you get the most up-to-date version of Cygwin? Easy. Just
download the Cygwin Setup program from http://cygwin.com/setup.exe.
This program will handle the task of updating the packages on your
system to the latest version. For more information about using
Cygwin's 'setup.exe', see Setting Up Cygwin in the Cygwin User's
Guide."

[Setting up Cygwin]
http://cygwin.com/cygwin-ug-net/setup-net.html

"Internet Setup"

"To install the Cygwin net release, go to http://cygwin.com/ and click
on 'Install Cygwin Now!'. This will download a GUI installer called
setup.exe which can be run to download a complete cygwin installation
via the internet. Follow the instructions on each screen to install
Cygwin."

[GNU + Cygnus + Windows = Cygwin]
http://cygwin.com/

"Install Cywin Now" button at upper right and also linked at least
three other places on the page.

"Latest Cygwin DLL release version is 1.5.10-3"

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

As a reality check I found the "tailored" instructions here quite
helpful.  Although the author is describing the installation of Cygwin
for a purpose other than Octave, it gave "depth" perspective to see
what a large beast the total Cygwin package is.  It _can_ provide a
Unix-like bash shell interface to Windows OS, but many of the standard
Unix commands are _not_ part of the "default" Cygwin installation, eg.
clear and less among other items described here:

[ftpSYNC Windows  Installation - Windows 9x , XP, NT running cygwin]
http://home.earthlink.net/~fredclrk/ftpsync/docs/install.html

It gives a checklist of commands to run from the bash prompt to verify
installation, and recommends adding a dialog/menu management engine
(link provided on that page).

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

That being said I opted for the default installation, using DOS-style
text files (vs. Unix-style, a radio button option on the setup's first
configuration screen), to the directory C:\cygwin.  Because I'd done
an Octave installation before, it seemed to pick up the "old"
(nonexistent) directory as the default this time, but warned me not to
choose a "root path" with embedded spaces (as in C:\Program
Files\...).

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

At the last screen of the setup program there are checkboxes to create
Start Menu and desktop icons for the Cygwin shell, which I accepted.

If you are running a firewall (as I do), you'll be alerted a few times
as the setup program and the Cygwin shell, at least the first time you
launch it, seek access to the Internet.  The shell in particular seems
to use uname and hostname to construct a default "prompt" string.

*  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *  *

Finally it must be admitted that the Octave package on my laptop
exhibits one annoying visual distraction, a scatter of black vertical
strokes (against a white background) delimiting my typing (but not in
general with the system's output to the screen).  I'd hoped upgrading
to the latest Cygwin package would eliminate this, but alas it did
not.

When necessary I minimize the window in which Octave is running and
restore it, which removes these display artifacts.


regards, mathtalk-ga

Clarification of Answer by mathtalk-ga on 24 Jul 2004 10:01 PDT
Because the reinstall of Cygwin didn't fix my annoying vertical stroke
display issue, I got busy and found a thread on the Web where the
problem is discussed and a work-around identified:

[Display problem in GNU-Octave on WindowsXP]
http://www.octave.org/octave-lists/archive/help-octave.2003/msg00591.html

Apparently the problem goes away if the shortcut properties of the
desktop icon that launches Octave are suitably modified.

As installed, the "command line" parameters of Octave use font Lucida
Console-12.  Changing this to Courier-12 (still a monospaced font)
eliminates the vertical strokes.  The total shortcut "target" on my
machine now reads:

"C:\Program Files\GNU Octave 2.1.50\bin\run.exe" rxvt.exe
--keysym.0xFF50 '^a' --keysym.0xFF57 '^e' --keysym.0xFFFF '^f^h' -fn
'Courier-12' -tn linux -title 'GNU Octave 2.1.50' -geometry 80x25 -sl
400 -sr -e /bin/start_octave.sh

regards, mathtalk-ga
xman-ga rated this answer:5 out of 5 stars
As soon as I saw mathtalk was on the problem I knew it was solved. An
excellent, thoroughly described and simple solution. Thankyou.
Thanks also for the comments provided by andyt and saem_aero.

Comments  
Subject: Re: converting MATLAB routine to an executable file
From: andyt-ga on 22 Jul 2004 17:13 PDT
 
Hi xman, mathtalk,
If you have the matlab developer edition, it comes with a compiler:
http://www.mathworks.com/products/compiler/
Subject: Re: converting MATLAB routine to an executable file
From: saem_aero-ga on 23 Jul 2004 07:45 PDT
 
Alternative suggestion.

If the original webpage is opened there is a link to c++ and FORTRAN
90 source code.  It could be possible to download this source code and
compile it with any of the free c++/ FORTRAN 90 compilers on the
Internet (GNU etc.).

Just a friendly comment. =)

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy