From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michael Brand Subject: Re: Insert calc vector directly into spreadsheet cells? Date: Tue, 27 May 2014 20:06:54 +0200 Message-ID: References: <87vbt04gq3.fsf@bzg.ath.cx> <7D34B671-E545-4AAF-A704-07D45B9A4715@acumeniacal.com> <94E4DBCE-2BEF-4766-A49F-D20DCE9ABB29@acumeniacal.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36254) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WpLm4-0007vm-Pq for emacs-orgmode@gnu.org; Tue, 27 May 2014 14:06:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WpLm3-0004Oc-VM for emacs-orgmode@gnu.org; Tue, 27 May 2014 14:06:56 -0400 Received: from mail-qc0-x22e.google.com ([2607:f8b0:400d:c01::22e]:64483) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WpLm3-0004OQ-OW for emacs-orgmode@gnu.org; Tue, 27 May 2014 14:06:55 -0400 Received: by mail-qc0-f174.google.com with SMTP id c9so6548286qcz.33 for ; Tue, 27 May 2014 11:06:55 -0700 (PDT) In-Reply-To: <94E4DBCE-2BEF-4766-A49F-D20DCE9ABB29@acumeniacal.com> 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: Steven Adrian Cc: Org Mode Hi Steven On Tue, May 27, 2014 at 11:12 AM, Steven Adrian wrote: > Here is the custom calc function that is similar to subscr. It will > work for both vectors and matrices: > > (defmath getElem (indices m) > (let (i j) > (if (vectorp indices) > (progn > (setq i (cadr indices)) > (setq j (nth 2 indices)) > (nth j (nth i m)) > ) > (progn > (setq i indices) > (nth i m) > ) > ) > ) > ) > > Here is the table function to get matrix data from a table, take the > inverse, and write the result to a new table: > > #+TBLFM: @1$1..@3$3=getElem([@#,$#],inv(arrange(remote(matrixTable,@1$2..@3$4),3)) Very nice. I didn't know the Calc function arrange([a, b, c, d], 2) to get [[a, b], [c, d]]. I always thought that when a TBLFM range spans more than one row and column like in @1$2..@2$3 it should learn to result in [[a, b], [c, d]] instead of the current [a, b, c, d]. Thanks for showing how to deal with this. Michael