Exporting matlab animations (mpeg, gif)

To create a movie file from a matlab animated figure do the following:

frames(1:nFrames) = struct('cdata', [], 'colormap', []);
for i=1:nFrames
  % Do your plotting

To convert the movie file into a gif use:

convert -crop 0x0 -loop 0 my_movie.avi my_movie.gif

Silent make by removing echo

To remove default output of make command start each line of the Makefile that you wish to ‘silence’ with ‘@’:

@rm -f *.o

This can cause problems when the compiler generates an error. In that case you need to catch the error and terminate the make process. You should also generate a message saying which command caused the problem since this command won’t be printed on the screen (The error message will show up though). Use following code to do just that:

    @echo "Compiling helloworld.cpp";
    @gcc helloworld.cpp $(CFLAGS) -o helloworld \
    || (echo "Error in command: gcc helloworld.cpp $(CFLAGS) -o helloworld" && false)

Compiling cython code as c++ (PySim)

Use following makefile as template:

CURDIR=$(shell pwd)../
PYXFLAGS=-I$(CURDIR)/api -I$(CURDIR)/include
CFLAGS+=-I$(CURDIR)/include -I$(CURDIR)/api
CFLAGS+=-Wno-write-strings -Wall -O2 -Os -fno-strict-aliasing -g
default: fri.so

fri.cpp: fri.pyx server.pyx libfri.h libfri.cpp
 cython fri.pyx -I. -I../api --cplus

fri.so: fri.cpp
 g++ -shared -o fri.so fri.cpp libfri.cpp friremote.cpp friudp.cpp -I/usr/include/python2.6 -DHAVE_TIME_STAMP_RECEIVE $(CFLAGS)
 rm -f fri.cpp

 rm -f frifirstapp frisecondapp test_fri
 rm -f *.o *.so fri.cpp

The “cython fri.pyx -I. -I../api –cplus” line creates fri.cpp.

Remember to use proper $(CFLAGS) as above.

ieee1394 (firewire) permissions on Linux

To to give certain group read/write access to firewire devices create new udev “*.rule” file in /etc/udev/rules.d/10.my_ieee1394.rule with following content:

KERNEL=="raw1394", NAME="%k", GROUP="video", MODE="0664"
KERNEL=="dv1394*", NAME="dv1394/%n", GROUP="video", MODE="0664"
KERNEL=="video1394*", NAME="video1394/%n", GROUP="video", MODE="0664"

“undefined reference to” error

One of possible causes of this error is incorrect linking order of libraries using gcc/g++.

Linking libraries before object files causes the error:

g++ -o $(LIBS) $(PROGRAM) $(OBJS)

Linking libraries after object files solves the problem:

g++ -o $(PROGRAM) $(OBJS) $(LIBS)

This is a solution for static library linking. Shared libraries should link both ways. Also order of respective libraries is important. If library A uses library B, library B has to linked first (-lB -lA).