1

I am trying to output a matlab/octave array as an org-mode table. So for an array/matrix like

a =[ 1 2; 3 4; 5 6];

I'd like to have a 3 by 2 org-mode table. I tried to just echo the array a as if in matlab, but it does not work. I am wondering how to make the output work.

More specifically, for an input array:

#+name: test-data
#+begin_src octave :session test_case :exports both
  a =[ 1 2; 3 4; 5 6];
#+end_src

#+RESULTS: test-data
: org_babel_eoe

I can generate its size as a table:

#+NAME: test-output-size
#+BEGIN_SRC octave :session test_case :results value :colnames yes :hline yes
  size(a)
#+END_SRC

#+RESULTS: test-output-size
| 3 | 2 |

But when I tried to print the array a itself as a table, I got no output:

#+NAME: test-output-value
#+BEGIN_SRC octave :session test_case :results value :colnames yes :hline yes
  a
#+END_SRC

#+RESULTS: test-output-value
: org_babel_eoe

I also tried disp(), to no avail. So my question is:

What is the proper way to output an array as a table?

(This is with the Emacs 26 in Ubuntu 20.04 LTS)

tinlyx
  • 1,276
  • 1
  • 12
  • 27

2 Answers2

2

Octave is peculiar (or maybe ob-octave is peculiar). In particular, the name ans seems to have special meaning. Try this:

#+name: test-data
#+begin_src octave :session test_case :exports both
  a =[ 1 2; 3 4; 5 6];
  ans = a
#+end_src

#+RESULTS: test-data
| 1 | 2 |
| 3 | 4 |
| 5 | 6 |
NickD
  • 27,023
  • 3
  • 23
  • 42
1

You can ask for the results to be the output (the default is value) and then use the disp option you already tried; place this

:results output

on the begin_src line.

éric
  • 261
  • 1
  • 3
  • I have found that this might not work to get table output. Instead, you might like to try `:results value table` and add the lin `1*a` as the last line of your src block. – éric Jun 04 '20 at 15:43