From mboxrd@z Thu Jan 1 00:00:00 1970 From: Tak Kunihiro Subject: orgtbl-to-matlab Date: Thu, 23 Oct 2014 22:47:24 +0900 (JST) Message-ID: <20141023.224724.49651895.tkk@misasa.okayama-u.ac.jp> Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:58038) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XhIjz-0001a8-VU for emacs-orgmode@gnu.org; Thu, 23 Oct 2014 09:47:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XhIjr-00057G-G7 for emacs-orgmode@gnu.org; Thu, 23 Oct 2014 09:47:47 -0400 Received: from scmgateway1.cc.okayama-u.ac.jp ([42.127.236.165]:9479) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1XhIjq-00055r-MX for emacs-orgmode@gnu.org; Thu, 23 Oct 2014 09:47:39 -0400 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Cc: tkk@misasa.okayama-u.ac.jp 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)))