Octave: make it as much MATLAB-compatible as possible - matlab

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.

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.

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.

Related

Transpose Coordinates to UTM84-17N Projection

In Swift, is there a way to input Lat/Long coordinates from MapKit, and translate those coordinates to a specified Projection, such as UTM84-17N (e.g. AutoCAD format)?
Well, I never did figure out how to do this using iOS/Swift, but I did discover a lisp code in both AutoCAD Map (two or three lines of code) and even better, in BricsCAD using the Spatial Manager extension (One single line of code).
For both, they involve three parameters: the source coordinates (in my case are in lat/long) the source projection code and the destination projection code.
The projection codes lists are provided in 'help.'
Actually, the company who owns Spatial Manager actually wrote the routine to fit into lisp for me when I posed the question to them; amazing!
So, there might be a manageable method that can be written for any platform.., who knows.
If anyone is interested in those lines of code to work in CAD, I'll look them up and post them.
By the way, a plug for BricsCAD: AutoCAD MAP from Autodesk, is now like almost $10,000 Canadian; BricsCAD is far less than $1000 for their best Pro option. NO BRAINER. AND, I find after being a guru in AutoCAD scripting for years, that BricsCAD is way better! AutoCAD is now so full of bloatware trinkets and useless stuff (similar to Windows' verification window pop ups) that it takes about 30 seconds just to load on a fast rig. And they have made things so much more difficult for old school users. Not to mention, the folks at BricsCAD are so incredibly helpful you feel like family with them!
...only one tiny flaw so far in going with them tho. They don't have a proper lisp editor (that I can find anyway), that lets you test the code line by line real time - like AutoCAD does...

Alternatives to extrinsic functions such as imread and other functions during code generation in MATLAB

As you may know, extrinsic functions are not outputted during the code generation process. Are there alternatives to these functions and/or solutions to this problem? My code generation error report is shown below :
Code Generation Error Report
I am surprised that I can't output size and rgb2gray either. Since these are essential to my program, I cannot avoid them.
Help will be much appreciated!
This is a good question, and I see similar questions fairly frequently. As I started using MATLAB Coder, one of the biggest pitfalls was the constant search for supported functions. I sympathize with your frustration, and I have a few tips, having been through this.
First, to your direct question, while imread isn't supported by Coder, size and rgb2gray are. Probably Coder is complaining about these because they have been passed mxArrays from the call to imread, which is fine when it is extrinsic, but not ok for separate generation. That's just a guess. A very useful tool in writing code is the list of Coder supported functions: List of Functions supported in MATLAB Coder
But even with those two, to replace imread is not a tiny task. You'll have to find another library that supports the particular file you're working with, and then stitch that in using coder.ceval. Alternatively, if you can find a pure MATLAB implementation of it, that might help.
Are you targeting a pure C library or a MEX file? If you intend to use this code within the MATLAB environment, you can always use imread separately and then pass the data.
And now to some more general observations: MATLAB Coder isn't a perfect MATLAB to C translation system. It's extremely powerful, and I've been able to write some very large projects with it, but if what you want is the ability to run any MATLAB code without MATLAB around, you should look at MATLAB Compiler, a different add-on. There's a very good Q and A about this here: MATLAB Compiler vs MATLAB Coder
When writing projects in MATLAB Coder, it's really best to start from scratch, knowing you're targeting C code ultimately. There are so many gotchas in the conversion from MATLAB to C that you have to be always vigilant while writing the MATLAB code.
One tool that helps is to right-click on a file in the "Current Folder" list that usually resides on the left-side of the main window, and select "Check Code Generation Readiness." You'll get a great report of potential problems in the file. I recommend using this often.
Another useful tool is to always put the %#codegen tag into your code. This alerts the MATLAB editor that the .m file is intended for code generation, so it provides extra context-sensitive information while you're writing the file. This helps enormously.
The most commonly missing functions for code generation are file IO functions. There are some good reasons for this, but it's frustrating nonetheless.
When you stitch in external C code, you use the coder.ceval function, which can provide excellent access to external libraries. Using this well is a whole other topic, outside the scope of this question.
If you can indicate exactly what kind of files you're interested in reading (PNG, BMP, TIFF, etc.) perhaps someone may be able to identify a good external library for you to use.

Matlab vs Aforge vs OpenCV

I am about to start a project in visual image-processing and have no had experience with Matlab, Aforge, OpenCV and was wondering if anyone had any experiences with these different software packages.
I was also wondering which of the three packages were most efficient I assume OpenCV but has anyone had any experience?
Thanks
Jamie.
The question you need to ask yourself is which is more important - your time or the computer's time. If your task is really simple, you may be able to code it up in MATLAB and have it work right off the bat. MATLAB is by far the easiest for development - a scripted language with built-in memory management, a huge array of provided functions, and a great interface for displaying and manipulating data while debugging.
On the other hand, MATLAB is at least an order of magnitude slower than compiled openCV code for many tasks. This is especially true if you use the intel performance primitives libraries.
If you know how to code in MATLAB, I would suggest writing and debugging your algorithms in that language, then porting them to c/c++ with openCV for speed. If there are only a couple of simple functions that you need to speed up, you can call c code from MATLAB, but it's hard to get this working right the first few times you try it, so you're probably better off just rewriting your finished code entirely in c/c++
First, please elaborate about your project's needs. It has the biggest impact on the choice, in addition to other factors - your general programming knowledge (If you haven't dealt with dot net but just with C++, AForge is not a good choice, for example).
Generally,
Both AForge and OpenCV has a built-in interface to .Net, and OpenCV also with C++, python, and more. Matlab might be more efficient, but if you don't have any experience with it - you should also learn its syntax. Take it into consideration.
Matlab probably has the largest variety of functions, but it is more complicated than the other projects. OpenCV and AForge themselves have some differences - see them described in this StackOverflow question/ answers.
I worked last year in two similar projects with cars on the highway. Afaik, Matlab allows to process only one picture frame at a time (surely you could elaborate an algorithm to compute a stream) but using Simulink you can process the stream directly.
On the other hand, i found AForge a lot friendlier and easier to use since you can easily adjust the processing parameters from a GUI (not so fast/easy) to do in Matlab/simulink.
I'd go for Aforge.Net. It's also fast enough if you're worrying about processing speed. (using 640x480)
If you are asking about using one of these in .net,easily you can get info by this:
1-matlab mostly used in simulation of projects not the End-prototype project; my numer : 30;
2-aforge (as I'v used in many project) if you do not need the circular process like capturing image, or recognition of something in images or ... you'll find it very good, cause it is easy to use but useful for single processes; my number : 50
3-opencv very good at speed and useful for circular processes, for example you can capture images from a webcam and Instantly cartoonize it without any delay, But not easy-to-use as aforge. I like it anyway cause of its speed and MANY functions it gives us mostly anything we need in programming; my number : 80
Dr.Taha - Tahasoft.net

Using MATLAB's plotting features as an interactive part of a Fortran program

Although many of you will have a decent idea of what I'm aiming at, just from reading the title -- allow me a simple introduction still.
I have a Fortran program - it consists of a program, some internal subroutines, 7 modules with its own procedures, and ... uhmm, that's it.
Without going into much detail, for I don't think it's necessary at this point, what would be the easiest way to use MATLAB's plotting features (mainly plot(x,y) with some customizations) as an interactive part of my program ? For now I'm using some of my own custom plotting routines (based on HPGL and Calcomp's routines), but just as part of an exercise on my part, I'd like to see where this could go and how would it work (is it even possible what I'm suggesting?). Also, how much effort would it take on my part ?
I know this subject has been rather extensively described in many "tutorials" on the net, but for some reason I have trouble finding the really simple yet illustrative introductory ones. So if anyone can post an example or two, simple ones, I'd be really grateful. Or just take me by the hand and guide me through one working example.
platform: IVF 11.something :) on Win XP SP2, Matlab 2008b
The easiest way would be to have your Fortran program write to file, and have your Matlab program read those files for the information you want to plot. I do most of my number-crunching on Linux, so I'm not entirely sure how Windows handles one process writing a file and another reading it at the same time.
That's a bit of a kludge though, so you might want to think about using Matlab to call the Fortran program (or parts of it) and get data directly for plotting. In this case you'll want to investigate Creating Fortran MEX Files in the Matlab documentation. This is relatively straightforward to do and would serve your needs if you were happy to use Matlab to drive the process and Fortran to act as a compute service. I'd look in the examples distributed with Matlab for simple Fortran MEX files.
Finally, you could call Matlab from your Fortran program, search the documentation for Calling the Matlab Engine. It's a little more difficult for me to see how this might fit your needs, and it's not something I'm terribly familiar with.
If you post again with more detail I may be able to provide more specific tips, but you should probably start rolling your sleeves up and diving in to MEX files.
Continuing the discussion of DISLIN as a solution, with an answer that won't fit into a comment...
#M. S. B. - hello. I apologize for writing in your answer, but these comments are much too short, and answering a question in the form of an answer with an answer is ... anyway ...
There is the Quick Plot feature of DISLIN -- routine QPLOT needs only three arguments to plot a curve: X array, Y array and number N. See Chapter 16 of the manual. Plus only several additional calls to select output device and label the axes. I haven't used this, so I don't know how good the auto-scaling is.
Yes, I know of Quickplot, and it's related routines, but it is too fixed for my needs (cannot change anything), and yes, it's autoscaling is somewhat quircky. Also, too big margins inside the graf.
Or if you want to use the power of GRAF to setup your graph box, there is subroutine GAXPAR to automatically generate recommended values. -2 as the first argument to LABDIG automatically determines the number of digits in tick-mark labels.
Have you tried the routines?
Sorry, I cannot find the GAXPAR routine you're reffering to in dislin's index. Are you sure it is called exactly like that ?
Reply by M.S.B.: Yes, I am sure about the spelling of GAXPAR. It is the last routine in Chapter 4 of the DISLIN 9.5 PDF manual. Perhaps it is a new routine? Also there is another path to automatic scaling: SETSCL -- see Chapter 6.
So far, what I've been doing (apart from some "duck tape" solutions) is
use dislin; implicit none
real, dimension(5) :: &
x = [.5, 2., 3., 4., 5.], &
y = [10., 22., 34., 43., 15.]
real :: xa, xe, xor, xstp, &
ya, ye, yor, ystp
call setpag('da4p'); call metafl('xwin');
call disini(); call winkey('return');
call setscl(x,size(x),'x');
call setscl(y,size(y),'y')
call axslen(1680,2376) !(8/10)*2100 and 2970, respectively
call setgrf('name','name','line','line')
call incmrk(1); call hsymbl(3);
call graf(xa, xe, xor, xstp, ya, ye, yor, ystp); call curve(x,y,size(x))
call disfin()
end
which will put the extreme values right on the axis. Do you know perhaps how could I go to have one "major tick margin" on the outside, as to put some area between the curve and the axis (while still keeping setscl's effects) ?
Even if you don't like the built-in auto-scaling, if you are already using DISLIN, rolling your own auto-scaling will be easier than calling Fortran from MATLAB. You can use the Fortran intrinsic functions minval and maxval to find the smallest and largest values in the data, than write a subroutine to round outwards to "nice" round values. Similarly, a subroutine to decide on the tick-mark spacing.
This is actually not so easy to accomplish (and ideas to prove me wrong will be gladly appreciated). Or should I say, it is easy if you know the rough range in which your values will lie. But if you don't, and you don't know
whether your values will lie in the range of 13-34 or in the 1330-3440, then ...
... if I'm on the wrong track completely here, please, explain if you ment something different. My english is somewhat lacking, so I can only hope the above is understandable.
Inside a subroutine to determine round graph start/end values, you could scale the actual min/max values to always be between 1 and 10, then have a table to pick nice round values, then unscale back to the correct range.
--
Dump Matlab because its proprietary, expensive, bloated/slow and codes are not easy to parallelize.
What you should do is use something on the lines of DISLIN, PLplot, GINO, gnuplotfortran etc.

Differences Between MATLAB 4.2c And The Lastest One

I'm now learning a bit of MATLAB and I have two versions of it. Version 4.2c, that I use on my emulated Windows 3.11 and the lastest one, that I use on my Windows Vista.
Here is a screenshot of it:
MATLAB 4.2c On My Windows 3.11 http://img9.imageshack.us/img9/4042/matlabv4.png
Then I want to know:
What are the main differences?
Are there are any differences in the language itself?
Will new libraries work?
EDIT: Now that I see the screenshot, I realize you really are referring to MATLAB Version 4.2c (R7). I thought perhaps you were mistakenly referring to the MATLAB Compiler instead, since I didn't think anyone would still be using a version that's over 15 years old! The oldest version I've used was when I first started learning MATLAB in 1996 on Version 5.0 (R8)!
The basic matrix and vector operations probably haven't changed much since Version 4.2c, although there are some newer functions to manipulate matrix data in different ways, like ACCUMARRAY, BSXFUN, and ARRAYFUN to name a few. Virtually everything else has probably changed in some subtle or not-so-subtle way: the MATLAB Desktop and Editor, graphics and plotting tools, creating graphical user interfaces, etc.. You can also do object-oriented programming now using MATLAB classes.
Anyhow, for all MATLAB releases starting from the newest Version 7.9 (R2009b) and going all the way back to Version 7 (R14, 2004) you can find the release notes on The MathWorks website. These release notes highlight the new features and bug fixes added to each MATLAB version since the previous release. For example, in order to see the difference between Versions 7.6 and 7.9, you'd have to look through the release notes from 7.7, 7.8, and 7.9. If you really need release notes going farther back in time, you will probably have to contact the MathWorks directly.
P.S. I may actually still have my old notes from my first MATLAB course, which I'm tempted to dig out of storage and take a look at just to see what may have changed since then. ;)
what isn't different?
I have no idea how much new has been added since then. I remember first learning about MATLAB around then and turning my nose up at the program... my guess is that you would find all the basic operations the same, because I remember these things working:
vector & matrix manipulation
elementary functions
basic plotting (e.g. plot, subplot functions)
.m file syntax
There's all sorts of stuff nowadays, particularly the toolboxes, things like the integrated debugger (breakpoints!) and profiler, just-in-time compilation (for-loops are much quicker now), GUI development, object-oriented syntax, Simulink, etc. etc.
You'll just have to try it and see... I have found in the last 10 years that there has been very little backwards compatibility trouble with matlab. The only thing I can remember that was challenging was some of the corner cases changed with handle graphics between v6 and v7.
There are a huge number of differences since that time. New variable types (logical, sparse, cell arrays, uint(N), single, etc.), objects, anonymous and nested functions, gui tools, toolbox changes galore.
Having said that, I have code written in 1988 (20+ years) that still runs with essentially no change. (Maybe version 3.5 or so?) And I just tripped recently over a piece of code from that era that is still actively being used.
The MathWorks does make great efforts to continue backwards compatibility for all code. Only under a great deal of discussion do they break that rule.