Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Octave: make it as much MATLAB-compatible as possible

Tags:

matlab

octave

I need to implement a couple of algorithms in MATLAB(homework), however I want to use GNU Octave instead. But I'd like to turn off any octave extensions, and basically turn it into FOSS-version of MATLAB. What settings should I change? What command-line options should I provide when executing octave program?

PS: I am aware of --traditional command-line option, although it doesn't seem to do much.

PPS: Any suggestions are welcome. If following your advice requires, for example, rebuilding octave from source, let it be.

like image 712
Alexander Putilin Avatar asked Aug 26 '12 00:08

Alexander Putilin


2 Answers

Aside using the --traditional option there's nothing you can do. Simply do not use the extra syntax that Octave offers. After all, Matlab syntax is a subset of the GNU Octave language, and it's up to you to use that subset only.

EDIT: It's not the answer you'd like but there's a good reason why that's an impossible task (by impossible, I mean very difficult. The only option is really to just fork Octave and change it until it's an exact clone. And you don't want to do it, trust me). Imagine the following very example. Octave has the functions 'rows' and 'columns' but Matlab does not. If you changed Octave so that these functions no longer exist, all other Octave functions that use them (I'm guessing a lot), will also stop working.

Others before you have successfully convinced their professors to accept homework written in Octave though, just make sure you at least try to write compatible code.

EDIT 2: I'll try to explain by comparing this situation with pianos (seems like a very good comparison). You can buy a piano with 85 or 88 keys. Now imagine that Matlab is a piano with 85 keys while Octave is a piano with 88 keys (if you want, also imagine that Matlab has 3 pedals while Octave only has 2 pedals). The only difference between the two pianos is that one has a slightly larger tonal range, i.e., it can play a few more tones (from the 3 extra keys). But when you play a C4 on a piano with 85 keys and a C4 on a piano with 88 keys, the sound is the same, they are the same note. The notes are the functions and keywords you have available. They are the same. A note in one piano is the same note on the other.

Now, if you are a composer writing music, you may want to take that in consideration. Just don't write any piece of music that requires those extra keys. The music will be the same in both types of pianos. If you have a piano with 88 keys, you will not chop off the 3 extra keys because you want it to be compatible with the 85 keys pianos. You simply don't play those keys. A piano with 88 keys is compatible with a piano with 85 keys, in the same way that Octave is compatible with Matlab.

If you want a guide to remind you that you can't use those extra keys, I'd guess you could put some red tape on them to remind you not to use them. Similarly, use Octave with a text editor that has different syntax highlight for Octave and Matlab so it will highlight incorrectly when you use syntax that is not part of Matlab. Aside that, there is nothing you can do (unless you count forking the Octave project, request Mathworks to implement them in Matlab or implementing them yourself. I don't mean this as rude sarcasm, just trying to be exhaustive).

For sake of completion, yes Octave has not implemented all Matlab things yet but it's moving that way as people develop it. It's not a static project (just take a look at the NEWS file for the development branch for example), things get implemented as the people who need them develop them. And some functions do behave differently but those are bugs you can report (and even fix since after all it's free and open source). Such incompatibilities are not there for the sake of annoying users. They are there because no one has reported or fixed them. Plus most of them are for incorrectly or undocumented Matlab features.

EDIT 3: you can also turn on the matlab incompatible warnings (which are off by default). Run warning ('on', 'Octave:matlab-incompatible'). You can leave this on your .octaverc file. To see more warnings look into warning_ids.

like image 117
carandraug Avatar answered Sep 18 '22 18:09

carandraug


I guess it is better to use a GUI that does it for you. I personally use Xoctave due to its support and Matlab like interface.

like image 32
Derek Maynhard Avatar answered Sep 22 '22 18:09

Derek Maynhard