Personal tools
You are here: Home log matlab
Document Actions

matlab

1   2009-10-5 MATLAB Intro

steps to start MATLAB

  1. source /usr/usc/matlab/2009a/setup.sh # PATH, license, etc.
  2. export MATLABPATH=~/script/variation/bin/GADA/mGADAr2 # so that matlab -nodisplay -r "function ..." could work

MATLAB index starts from 1 (same as R), NOT 0, for any list or array.

2   2009-10-5 MATLAB commands

Table 1 MATLAB commands
command description more date_created
whos inspect a variable, type, dimension, attributes   2006-10-5

3   2009-8-19 write c extensions

flowchart of function calls

Matlab function => Mex-function, like a wrapper (c-code) => C-function (c-code)

According to Roger, need extra matlab libraries to compile matlab code into standalone programs.

4   2009-8-19 commandline arguments for matlab script

If you want to use the current terminal to enter commands but have the full environment available if required use matlab -nodesktop; If you do not plan to use the graphical environment at all then use matlab -nodisplay -nojvm.

A typical commandline would look like:

matlab -nodisplay -nojvm  -r "myfunc parameter1 parameter2 parameter3"

myfunc has to be in MATLABPATH or in current directory.

Link with files regarding how to run Matlab scripts (standalone, compilation, etc): http://www.wrg.york.ac.uk/docs/installed-software/matlab

5   2009-10-4 compile mex code

Roger uses c++ comment style // in his c files. By default, matlab adds -ansi to CFLAGS which forces gcc to exit upon encountering //. So need to override that option first.

  1. Run below and choose gccopts.sh

    /usr/usc/matlab/default/bin/mex -setup

  2. modify ~/.matlab/R2008a/mexopts.sh to remove -ansi from CFLAGS (there're several of them for different architectures).

  3. Run matlab -nodisplay -nojvm -r "MakeMex" to compile all c extentions.

6   2009-10-5 memmapfile

6.1   2009-10-5 creation of memmapfile from python

A binary output is good enough.:

outf = open(output_fname, 'wb')
import numpy
data_matrix = numpy.transpose(data_matrix)      #somehow, without this, matlab will read it as transposed to the original matrix 
data_matrix.tofile(outf, format='%.8f') # format seems to not matter.
""" #2009-10-5 output directly through file write
no_of_rows, no_of_cols = data_matrix.shape
for i in range(no_of_rows):
        for j in range(no_of_cols):
                outf.write(struct.pack('d', data_matrix[i,j])
"""
del outf

6.2   2009-10-5 type of variable used to specify dimension in formatspec has to be double

To increase flexibility, [10 20] is replaced by something like [M N] to specify dimension on the runtime. Then the type of M or N becomes an unexpected issue. It turns out be to double, rather than any integer type. It was found out by N=10; whos N;.:

M = double(str2num(varargin{6}));     %% no. of probes.
N = double(str2num(varargin{7}));     %% no. of samples
memmap_fname = input_fname; % 'mytemp.tmp';
Ymat2=memmapfile(memmap_fname, 'format', {'double', [M N], 'x'});     % the last 'x' means the matrix will be accessed as Ymat2.Data.x
« November 2009 »
Su Mo Tu We Th Fr Sa
1234567
89101112 1314
1516171819 20 21
22232425262728
2930
 

Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: