emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orgmode] [babel] Octave and Matlab support


From: Dan Davison
Subject: [Orgmode] [babel] Octave and Matlab support
Date: Thu, 18 Mar 2010 15:47:34 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux)

I've added support for Octave and Matlab to org-babel.

In addition to the normal org-babel setup[1], you'll need one or both of

(require 'org-babel-octave)
(require 'org-babel-matlab)

and for matlab sessions you'll need matlab.el[2] (octave support is
bundled with GNU emacs).

I'd appreciate the help of octave/matlab users in sorting out the
remaining issues with this (many of which will be due to my lack of
octave/matlab knowledge). So please report back all the problems you
find!

I'm attaching an org file containing notes on the problems that I'm
aware of. This will also (within a couple of hours) be available on
Worg[3], and it would be great if others could contribute to that
file. The intention is that file will turn into the language-specific
documentation for org-babel octave/matlab.

Dan

Footnotes:

[1] http://orgmode.org/worg/org-contrib/babel/intro.php#getting-started
[2] http://sourceforge.net/projects/matlab-emacs/
[3] 
http://orgmode.org/worg/org-contrib/babel/languages/org-babel-doc-octave-matlab.php

#+OPTIONS:    H:3 num:nil toc:2 \n:nil @:t ::t |:t ^:{} -:t f:t *:t TeX:t 
LaTeX:t skip:nil d:(HIDE) tags:not-in-toc
#+STARTUP:    align fold nodlcheck hidestars oddeven lognotestate hideblocks
#+SEQ_TODO:   TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@)
#+TAGS:       Write(w) Update(u) Fix(f) Check(c) noexport(n)
#+TITLE:      Org-babel-octave-matlab
#+AUTHOR:     Dan Davison
#+EMAIL:      davison at stats dot ox dot ac dot uk
#+LANGUAGE:   en
#+STYLE:      <style type="text/css">#outline-container-introduction{ 
clear:both; }</style>

This file contains notes on the support for matlab and octave in
org-babel. As these get sorted out, hopefully this document will turn
into the documentation for these languages.

Some of the current problems (e.g. 
[[*TODO%20How%20to%20detect%20if%20result%20is%20numeric%20or%20string][this 
one]] and 
[[*TODO%20Ensure%20that%20value%20is%20returned%20when%20expected][this one]]) 
stem from
the extremely simple code being used to write results to file. Here
the first %s is replaced with the body of the block, and the second %s
with a temp file name.

#+begin_src emacs-lisp 
(defvar org-babel-octave-wrapper-method
  "%s
save -ascii %s ans")
#+end_src

As noted below, this needs to be made more sophisticated, in
particular to detect whether 'ans' is an object for which save -ascii
is appropriate (e.g. an array) or not (e.g. a string).

* TODO How to detect if result is numeric or string?
     - State "TODO"       from ""           [2010-03-18 Thu 12:37]

       Currently strings are being returned as their ascii codes:

#+begin_src octave
  'ab'
#+end_src

#+results:
: 9.70000000e+01 9.80000000e+01

* TODO How to divert graphical output to file?
  - State "TODO"       from ""           [2010-03-17 Wed 23:3

    Currently we are like pyuthoin and ruby in that we can
    use :results file and the block will output a link to that file,
    but unless your code takes care of it (e.g. write graphics to
    file), no content will be written to that file.

    However, would it be appropriate to move to the org-babel-R model,
    whereby if :results file is supplied, any graphical is
    automatically diverted to that file?
    
* TODO How to get rid of the matlab splash message
  - State "TODO"       from ""           [2010-03-18 Thu 01:09]

    -nosplash doesn't seem to do the trick.

* TODO Ensure that value is returned when expected
     - State "TODO"       from ""           [2010-03-18 Thu 13:57]

       In :results value mode, we return whatever value the variable
       'ans' has at the end of the block. However, there are some
       problems with this as can be seen from the following session:

#+begin_example 
octave> 'hello'
ans = hello
octave> ans
ans = hello
octave> x = 19
x =  19
octave> x
x =  19
octave> ans
ans = hello
#+end_example

So although this works as expected:

#+begin_src octave :var z=67
  z + 0
#+end_src

#+results:
: 6.70000000e+01

This doesn't

#+begin_src octave :var z=67
  z
#+end_src

#+results:
: 4.70000000e+01 1.17000000e+02 1.15000000e+02 1.14000000e+02 4.70000000e+01 
1.15000000e+02 1.04000000e+02 9.70000000e+01 1.14000000e+02 1.01000000e+02 
4.70000000e+01 1.11000000e+02 9.90000000e+01 1.16000000e+02 9.70000000e+01 
1.18000000e+02 1.01000000e+02 4.70000000e+01 1.12000000e+02 9.70000000e+01 
9.90000000e+01 1.07000000e+02 9.70000000e+01 1.03000000e+02 1.01000000e+02 
1.15000000e+02 4.70000000e+01 5.10000000e+01 4.60000000e+01 5.00000000e+01

  As part of its internal operation, org-babel appends a special
  end-of-output string at the end of each block and it is this
  string's value (integer ascii codes) that is being returned here.

Of course, this works

#+begin_src octave :var ans=67
  ans
#+end_src

#+results:
: 6.70000000e+01

* TODO Allow multiple sessions
  - State "TODO"       from ""           [2010-03-16 Tue 22:12]

* TODO Should we use these by default to save external process startup time?
  - State "TODO"       from ""           [2010-03-18 Thu 01:27]
  - -nodisplay ?
  - -nojvm ?

* TODO How to implement :results pp, :results code?
  - State "TODO"       from ""           [2010-03-18 Thu 01:10]

* TODO submit patch to matlab.el so that matlab session can be remote
    - State "TODO"       from ""           [2010-03-18 Thu 01:29]
      
      At the moment I'm using a massive hack: insert

 (cd "/address@hidden:") ;; DED

 around line 4253 in matlab.el so that my matlab sessions run on a
 machine with matlab installed.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]