Org-babel-octave-matlab
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. this one and 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.
(defvar org-babel-octave-wrapper-method "%s save -ascii %s ans")
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).
Table of Contents
- How to detect if result is numeric or string?
- How to divert graphical output to file?
- How to get rid of the matlab splash message
- Ensure that value is returned when expected
- Allow multiple sessions
- Should we use these by default to save external process startup time?
- How to implement :results pp, :results code?
- submit patch to matlab.el so that matlab session can be remote
DONE How to detect if result is numeric or string?
-
State "TODO" from ""
Strings were being returned as their ascii codes.
We have adopted Darlan's suggestion of using save -text %s ans (and delting the comment lines), which seems to provide a solution.
'octave string'
octave string
'string from matlab'
1.1500000e+02 1.1600000e+02 1.1400000e+02 1.0500000e+02 1.1000000e+02 1.0300000e+02 3.2000000e+01 1.0200000e+02 1.1400000e+02 1.1100000e+02 1.0900000e+02 3.2000000e+01 1.0900000e+02 9.7000000e+01 1.1600000e+02 1.0800000e+02 9.7000000e+01 9.8000000e+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 ""
-nosplash doesn't seem to do the trick.
TODO Ensure that value is returned when expected
-
State "TODO" from ""
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:
octave> 'hello' ans = hello octave> ans ans = hello octave> x = 19 x = 19 octave> x x = 19 octave> ans ans = hello
So although this works as expected:
z + 0
6.70000000e+01
This doesn't
z
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
ans
6.70000000e+01
TODO Allow multiple sessions
- State "TODO" from ""
TODO Should we use these by default to save external process startup time?
- State "TODO" from ""
- -nodisplay ?
- -nojvm ?
TODO How to implement :results pp, :results code?
- State "TODO" from ""
TODO submit patch to matlab.el so that matlab session can be remote
-
State "TODO" from ""
At the moment I'm using a massive hack: insert
(cd "/ddavison@tombstone.princeton.edu:") ;; DED
around line 4253 in matlab.el so that my matlab sessions run on a machine with matlab installed.