matlab

Matlab WTF: Inconsistent short-circuit behavior of logical operators

24 September, 2009 - 09:38
Categories:

I just stumbled on another reason to dislike Matlab: the stupid inconsistency of the short-circuit behavior of the elementwise logical operators: the statement

fun(2) | fun(9999)

does not short-circuit, so both fun(2) and fun(9999) are executed, but when used in an if or while expression like

if fun(2) | fun(9999); end;

the expression does short-circuit, meaning that only fun(2) is executed.

I know, you also have the || and && operators, which are defined as short circuiting operators, but the inconsistency with the | and & operators is just stupid, if not evil.

Read more...

C++-MEX files compilation problems under Ubuntu 8.04 (Hardy)

23 September, 2009 - 18:09

How unpleasant I may find it, sometimes I have to use some tools in Matlab at work. Today I stumbled on a problem with compiling MEX-files written in C++ on my Ubuntu 8.04 (Hardy Heron) box. To illustrate, I'll use the example C++ MEX file mexcpp.cpp provided with Matlab (Matlab r2007a) in the extern/examples/mex/ folder.

Out-of-the-box compilation with

mex mexcpp.cpp

gave the following warning:
Warning: You are using gcc version "4.2.4". The earliest gcc version supported with mex is "4.0.0". The latest version tested for use with mex is "4.2.0". To download a different version of gcc, visit http://gcc.gnu.org

Despite the warning a MEX-file mexcpp.mexglx was generated. However, its usage resulted in the following:
Invalid MEX-file '/foo/bar/mexcpp.mexglx': /matlabdir/sys/os/glnx86/libstdc++.so.6: version `GLIBCXX_3.4.9' not found (required by /foo/bar/mexcpp.mexglx).
As a sidenote: compiling MEX-files written in C also caused the warning message, but using the compiled MEX-files did not fail.

Read more...