How can I convert Matlab code to c#?

converting MATLAB routine to an executable file

  • 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.

  • Answer:

    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.

xman-ga at Google Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.