help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Matrix index, Please e-mail back.


From: Jordi Gutierrez Hermoso
Subject: Re: Matrix index, Please e-mail back.
Date: Wed, 6 Dec 2006 13:13:05 -0600

On 06/12/06, Jorgen Andersson <address@hidden> wrote:
Thanks to both of you.
My code works now!
I used one large index/mapping matrix 18432 x 32 to get to data in a 2048 x
9 matrix.
The time used to run the code changed from 180sec (for loop) to 10sec
(index/mapping)!

A muse visited me last night in my dreams and gave me a more obvious solution:

    octave:1> A = [1:100];
    octave:2> A = reshape(A,10,10)
    A =

         1   11   21   31   41   51   61   71   81   91
         2   12   22   32   42   52   62   72   82   92
         3   13   23   33   43   53   63   73   83   93
         4   14   24   34   44   54   64   74   84   94
         5   15   25   35   45   55   65   75   85   95
         6   16   26   36   46   56   66   76   86   96
         7   17   27   37   47   57   67   77   87   97
         8   18   28   38   48   58   68   78   88   98
         9   19   29   39   49   59   69   79   89   99
        10   20   30   40   50   60   70   80   90  100


    #I'm not sure if all versions of Octave support this kind of indexing, but
    #at least version 2.1.73 and probably later does.
    octave:3> D = [diag(A,-1)(1:end-2)'; diag(A,-2)(1:end-1)'; diag(A,-3)']
    D =

        2  13  24  35  46  57  68
        3  14  25  36  47  58  69
        4  15  26  37  48  59  70

I'm not sure if this is any faster, but it's worth a try. It's
certainly more concise to write it this way, and we all know that the
more concise the code, the better. ;-)

- Jordi G. H.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]