0

Is there a simple way to remove specific rows/columns of an Org table when passing them to a Babel block?

For example, I'd like to process the data in the table below using Matlab. The column headers are automatically removed, but I also need the row 'headers' on the left to organize the data before processing.

#+name: test-table
|            | colheader1 | colheader2 |
|------------+------------+------------|
| rowheader1 |          2 |          8 |
| rowheader2 |          4 |         10 |
| rowheader3 |          6 |         12 |

#+begin_src matlab :var x=test-table
a = x;
ans = a
#+end_src

If the leftmost column with 'headers' were removed, Matlab would receive the matrix [2 8;4 10;6 12], and the result would be:

#+results:
| 2 |  8 |
| 4 | 10 |
| 6 | 12 |

However, I get no result, presumably since Matlab doesn't know how to process a matrix with text and numerics without some type of cell classification.

1 Answer 1

0

I don't have matlab - here's a python version:

#+name: test-table
|            | colheader1 | colheader2 |
|------------+------------+------------|
| rowheader1 |          2 |          8 |
| rowheader2 |          4 |         10 |
| rowheader3 |          6 |         12 |

#+begin_src python :results value :var x=test-table[,1:2]
    return x
#+end_src

#+RESULTS:
| 2 |  8 |
| 4 | 10 |
| 6 | 12 |

See Environment of a Code Block.

1
  • 1
    Yes, the [,1:2] syntax worked for Matlab as well.
    – tdstoff
    Sep 29, 2022 at 15:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.