[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[O] orgtbl-to-matlab
From: |
Tak Kunihiro |
Subject: |
[O] orgtbl-to-matlab |
Date: |
Thu, 23 Oct 2014 22:47:24 +0900 (JST) |
Since LaTeX + radiotable is so comfortable, I start to use it on
MATLAB coding. The translator may be useful for some and I want to
let you know.
%{
#+ORGTBL: SEND tbl:radiotable orgtbl-to-matlab :no-escape t
| x | y | symbol |
|------+-------+--------|
| 0.79 | 0.243 | + |
| 0.78 | 0.230 | x |
| 0.78 | 0.242 | . |
%}
% BEGIN RECEIVE ORGTBL tbl:radiotable
x = [0.79 0.78 0.78];
y = [0.243 0.230 0.242];
symbol = {'+','x','.'};
% END RECEIVE ORGTBL tbl:radiotable
(defun orgtbl-to-matlab (table params)
"Convert the orgtbl-mode table to MATLAB statements."
(let* ((*list-is-num* org-table-last-alignment)
(*table-flip* (orgtbl-to-orgtbl-flip table))
(*index* (number-sequence 0 (1- (length *table-flip*)))))
(mapconcat (lambda (ii) (orgtbl-to-matlab--column
(nth ii *table-flip*) params (nth ii
*list-is-num*)))
*index* "\n")))
(defun orgtbl-to-matlab--column (table-nth-col params is-num-p)
"Convert a column of the orgtbl-mode table to a MATLAB statement."
(let ((params2 (list
:lstart (if is-num-p "[" "{'")
:sep (if is-num-p " " "','")
:lend (if is-num-p "];" "'};")
:no-escape t))
(*var-name* (car table-nth-col))
(*dataset* (cdr table-nth-col)))
(if is-num-p ;; return NaN when a cell in orgtbl is empty
(setq *dataset* (mapcar
(lambda (x) (if (string= x "") "NaN" x)) *dataset*)))
(format "%s = %s"
*var-name*
(orgtbl-to-generic (list *dataset*) (org-combine-plists params2
params)))))
(defun orgtbl-to-orgtbl-flip (table)
"Flip the orgtbl-mode table."
(with-temp-buffer
(insert (orgtbl-to-orgtbl table nil))
(goto-char (1+ (org-table-begin)))
(org-table-transpose-table-at-point)
(goto-char (1+ (org-table-begin)))
(org-table-to-lisp)))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [O] orgtbl-to-matlab,
Tak Kunihiro <=