Archive

Posts Tagged ‘matlab’

MATLAB on Ubuntu: From Install, Make launching Icon,… to Uninstall

February 12, 2012 1 comment

Here are the steps to install MATLAB + some possible problems:

  1. Extract/mount the zipped/iso installer file. For me I extract the iso to /home/bot/Downloads/Software/ml2011bu
  2. Open the terminal (Ctrl+Alt+T), type sudo sh install
    1. You might run into the problem say:Preparing installation files …
      Installing …
      eval: 1: /tmp/mathworks_2931/sys/java/jre/glnx86/jre/bin/java: Permission denied
      Finished
      bot@bot-laptop:~/Downloads/Software/ml2011bu$ cd sys

      What you need to do is to make the file “java” executable by
      from your installer folder, type

      cd sys/java/jre/glnx86/jre/bin/
      chmod +x java

      you will see that the file permission is changed from
      -rw-r–r– 1 bot bot  47308 2010-10-20 04:41 java
      to
      drwx–x–x 4 bot bot    4096 2012-02-11 17:55 java

      Now go back to the installer folder and install it with sudo sh install, and it should work

    For more details on installation, please visit
    https://help.ubuntu.com/community/MATLAB

Once the installation is finished, you may want to create a script to run the MATLAB. Here is how

  1. Go to desktop (where else is fine too)
  2. Create an empty document, let’s name it runmatlab.sh
  3. Open runmatlab.sh with gedit, and type the following
    cd /usr/share/matlabr2010a/bin/
    sudo sh matlab -desktop
  4. Open the terminal, go to desktop by typing in the terminal cd ~/Desktop
  5. make the script executable by typing in the terminal chmod +x runmatlab.sh
  6. Now you can run MATLAB by running the script by typing ./runmatlab.sh

Now, if you want to add a launching icon on the menu bar, here is how:

  1. Right click on the menu bar
  2. Edit menus>Go to Programming in the left panel
  3. Click new item and add all the information
  4. In the command, type /home/bot/Desktop/runmatlab.sh
  5. You can also change the icon by clicking at the icon on the top-left corner and choose where the icon is
    1. Here is an easy command line to download the icon
      sudo wget http://upload.wikimedia.org/wikipedia/commons/2/21/Matlab_Logo.png -O /usr/share/icons/matlab.png
    2. The icon will be downloaded to /usr/share/icons/matlab.png
  6. That’s it!

And, if you are bored with MATLAB and want to uninstall it, please follow the steps here

  1. Locate the matlab dir, mine is /usr/local/MATLAB
  2. Remove the matlab dir by
    >cd /usr/local
    >sudo rm -r MATLAB
  3. bye bye MATLAB, and you get 5GB more space hahahaha!
Advertisements
Categories: Tutorials Tags: ,

Install MATLAB r2010a on Ubuntu 10.04

January 13, 2012 Leave a comment

Here is the step by step how to install MATLAB on Ubuntu

  1. Mount the matlab iso file. Let’s say the matlab installation files are in directory /tmp/mat2010a
  2. First, install using
    $ sudo sh install
    However, you might get the error, which looks like this
    ——————————————————————-    An error status was returned by the program ‘xsetup’,
        the X Window System version of ‘install’. The following
        messages were written to standard error:

            /home/bot/tmp/matu20Xa/update/install/main.sh: 178: /home/bot/tmp/mat2010a/update/bin/glnxa64/xsetup: Permission denied

        Attempt to fix the problem and try again. If X is not available
        or ‘xsetup’ cannot be made to work then try the terminal
        version of ‘install’ using the command:

                install* -t    or    INSTALL* -t

    ——————————————————————-
    The problem occurs because of the permission of the file …/xsetup is not set properly. So, the easy way is to go to the directory and change the permission by using the command

    ../glnxa64$ chmod 777 xsetup

    Now, you can go back to the normal installation

  3. Next step, create a root matlab folder, and it is suggested that you create the folder in/usr/local/matlabR2010a

    by using the command line

    sudo mkdir /usr/local/matlabR2010a
  4. The rest is easy..you can do it yourself

Additional reading:
https://help.ubuntu.com/community/MATLAB/R2010a

Categories: Research, Tutorials Tags: ,

Install MATLAB and its launcher on Ubuntu

January 13, 2012 Leave a comment
Categories: Tutorials Tags:

How to remove white-border from a figure?

August 5, 2011 Leave a comment

When adding a figure to your publication, you might want to remove the undesired white-border off your figures. I believe that the best way is to create figures without the border if it is possible. In MATLAB, I think you can do so. However, if you have the figures already, you might want to have a program to remove the borders automatically, wisely and controllably. I developed a toolbox in MATLAB for this purpose. Please refer to the URL below.

https://sites.google.com/site/kittipat/bot_silly_tools

The overview of white-border removal toolbox

Plot 3D ellipsoid

August 4, 2011 1 comment

Plot 3D Gaussian distribution? The harder part is to plot the 3D ellipsoid which can be done by calculating the axes (radii) of the ellipsoid from its eigenvalues. Simultaneously, We will get its corresponding eigenvectors which tells how to rotate the ellipsoid. The function ellipsoid(.) can plot canonical ellipsoid, and hence we need to rotate the canonical ellipsoid using the eigenvectors. That is it. Here are some codes adapted from Rajiv Singh’s version.

% plot 3D ellipsoid
% developed from the original demo by Rajiv Singh
% http://www.mathworks.com/matlabcentral/newsreader/view_thread/42966
% 5 Dec, 2002 13:44:34
% Example data (Cov=covariance,mu=mean) is included.

Cov = [1 0.5 0.3
       0.5 2 0
       0.3 0 3];
mu = [1 2 3]';

[U,L] = eig(Cov);
% L: eigenvalue diagonal matrix
% U: eigen vector matrix, each column is an eigenvector

% For N standard deviations spread of data, the radii of the eliipsoid will
% be given by N*SQRT(eigenvalues).

N = 1; % choose your own N
radii = N*sqrt(diag(L));

% generate data for "unrotated" ellipsoid
[xc,yc,zc] = ellipsoid(0,0,0,radii(1),radii(2),radii(3));

% rotate data with orientation matrix U and center mu
a = kron(U(:,1),xc); 
b = kron(U(:,2),yc); 
c = kron(U(:,3),zc);

data = a+b+c; n = size(data,2);

x = data(1:n,:)+mu(1); 
y = data(n+1:2*n,:)+mu(2); 
z = data(2*n+1:end,:)+mu(3);

% now plot the rotated ellipse
% sc = surf(x,y,z); shading interp; colormap copper
h = surfl(x, y, z); colormap copper
title('actual ellipsoid represented by mu and Cov')
axis equal
alpha(0.7)

Using recursion in MATLAB

July 25, 2011 Leave a comment

This week I wind up with coding sum-product algorithm in MATLAB. All went well, and there were some interestingly simple but powerful techniques I would like to share. We all know that programming function with recursion can save a lot of time, and is a classic technique in C++. I just realized that we can do so in MATLAB too, and the way to do it is very similar to that in C++.

Example1: “Calculate the summation at each node in a binary tree”

I have a 3-level binary tree whose nodes are connected as follows: node1 is the parent of node 2 and 3, node 2 is the parent of node 4 and 5, node 3 is the parent of node 6 and 7. Let’s assume that nodes 4 – 7 are instantiated with number 4, 5, 6 and 7 respectively. We want to calculate for a node n the summation of its corresponding children in the leaf level. Let’s name the function fn_recurs_sum_tree(tree, n) where the variable “tree” is the binary tree structure with node 4-7 instantiated as above, and n denotes the node of interest. More specifically, tree is a cell array of the size 7 x 1, where tree{n} returns the value stored in the node n of the tree. Here is the example of the code

function sum = fn_recurs_sum_tree(tree,n) if ~isempty(tree{n,1})     sum = tree{n,1}; else     sum = fn_recurs_sum_tree(tree,2*n) + fn_recurs_sum_tree(tree,2*n+1); end 

Example2: “Calculate the summation at every node in a binary tree”

What if we want to find the summation at every node in the network? Of course, we would not call the function fn_sum_bin_tree(tree, n) for n=1, 2 and 3 as that would not be efficient when the number of node is large. One technique is to call the function at the root node (i.e., n = 1) so that all the summation is accumulated from bottom to the top. The price to pay is to deal with how to pass the cell array tree into such a function. Here is the example.

function [sum, tree] = fn_recurs_sum_tree2(tree,n) if ~isempty(tree{n,1})     sum = tree{n,1}; else     [sum1, tree] = fn_recurs_sum_tree2(tree,2*n);     [sum2, tree] = fn_recurs_sum_tree2(tree,2*n+1);     sum = sum1 + sum2;     tree{n,1} = sum; end 

Here are some test codes:

% #### example code ######
% initial the tree
tree = cell(7,1);
for n = 4:7
    tree{n,1} = n;
end

% Calculate the sum for a single node 2
sum = fn_recurs_sum_tree(tree,2)

% Calculate the sum for the whole network
[sum, tree] = fn_recurs_sum_tree2(tree,1)

This technique is very useful when you have to deal with tree. So, hope this helps! Sample codes are made available here:

fn_recurs_sum_tree.m
fn_recurs_sum_tree2.m
example1.m

Just copy all the codes, put them in the same folder, then run example1.

Hand posture recognition using minimum divergence classifier

May 8, 2011 4 comments

I and my colleague were suggested by a reviewer to apply our accepted work on some real-world application. “Bro, we’ve got less than 4 days to apply our work on a real-world problem…what would we do?”, we spent 10 minutes discussing several possible problems such as automatic video segmentation, CD cover searching, human gesture recognition and some other funny-crazy ideas. Finally, with our curiosity and the time constraint we ended up with static hand posture recognition. Fortunately, the data set is not too difficult to find on internet. Millions thanks to Triesch and Von Der Malsburg for the wonderful hand posture database–that saved our lives.

Originally we found that calculating divergence measure of 2 Gaussian mixture models (GMM) can be done efficiently using Cauchy-Schwarz divergence (D_{CS}) as it gives closed-form expression for any pair of GMMs. Of course, we can’t get this awesome property in Kullback-Leibler divergence (D_{KL})…why? read our paper [1] ^_^ Yay! In short, D_{KL} formulation does not allow Gaussian integral trick, hence closed-form expression is not possible.

In this work, we use minimum divergence classifier to recognize the hand postures. Please see our paper for more details. We had finished our experiment on the second day, so we have some time left to make a fancy plot summarizing our work which we would like to share with you below. The classification accuracy using D_{CS} and D_{KL} are 95% and 92% respectively, and the former method also gives much better computational run-time, about 10 time faster. The figures below also suggest that our proposed method outperforms D_{KL} when it comes to clustering as the proposed method gives more discriminative power.

Similarity matrix calculated by Cauchy-Schwarz divergence
Similarity matrix calculated by Kullback-Leibler divergence

[1] K. Kampa, E. Hasanbelliu and J. C. Principe, “Closed-form Cauchy-Schwarz pdf Divergence for Mixture of Gaussians,” Proc. of the International Joint Conference on Neural Networks (IJCNN 2011). [pdf] [BibTex]

We make our code available for anyone under
 creative commons agreement [.zip]

We also collected some interesting links to the hand posture/gesture database here:

http://www.datehookup.com/content-analyzing-body-language-gesture-recognition.htm
http://www-prima.inrialpes.fr/FGnet/data/03-Pointing/index.html#Gesture%20Vocabulary
http://www.idiap.ch/resource/gestures/
http://www.iis.ee.ic.ac.uk/~tkkim/ges_db.htm
ftp://mi.eng.cam.ac.uk/pub/CamGesData/
http://www.csc.kth.se/~danik/gesture_database/

The following papers and documents can be helpful:

A Bimodal Face and Body Gesture Database for Automatic Analysis of Human Nonverbal Affective Behavior
Hatice Gunes and Massimo Piccardi Computer Vision Research Group,
University of Technology, Sydney (UTS)

A Color Hand Gesture Database for Evaluating and Improving Algorithms on Hand Gesture and Posture Recognition
FARHAD DADGOSTAR, ANDRE L. C. BARCZAK, ABDOLHOSSEIN SARRAFZADEH

Hand Detection and Gesture Recognition using ASL Gestures
Supervisor: Andre L. C. Barczak
Student: Dakuan CUI
Massey University