Support via Liberapay, GitHub or PayPal


Table of Contents

This file contains notes on using Matlab and Octave with Org-babel.

An example of an octave block in Org-babel is

#+begin_src octave :exports results
,n = [1:10];
,x = 5*n+4;
,ans = x

,| 9 | 14 | 19 | 24 | 29 | 34 | 39 | 44 | 49 | 54 |

Notice that the final line is "ans = x". Finishing the block with the simple statement "x" will not work. In Org-babel, Matlab and Octave return the result of the special variable "ans", which (in Octave at least) is automatically updated with "The most recently computed result that was not explicitly assigned to a variable". Therefore, both "ans =x" and "x + 0" would result in the desired result being returned, "x" alone will not.

Graphical output

In order to get graphical output without leaving open graph windows during evaluation, the following can be used:

figure( 1, "visible", "off" );
print -dpng chart.png;
ans = "chart.png";

The figure command opens an invisible graph window where the next plot commands should act.

Then, the print command exports the graph to a file.

:results file says to interpret the result as a file path.

Documentation from the orgmode.org/worg/ website (either in its HTML format or in its Org format) is licensed under the GNU Free Documentation License version 1.3 or later. The code examples and css stylesheets are licensed under the GNU General Public License v3 or later.