help-octave
[Top][All Lists]
Advanced

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

Re: Efficient definition of multidimensional ranges


From: Doug Stewart
Subject: Re: Efficient definition of multidimensional ranges
Date: Fri, 8 Jun 2012 21:16:55 -0400



On Fri, Jun 8, 2012 at 8:41 PM, stn <address@hidden> wrote:

There are many ways of doing this, so here is one suggestion!!! 
 
...
and make a script file (ind.m) that is this:


Hi Doug,

yes that was it. The following shell-script can be given a string of pairs of numbers, with each pair defining one set.


#!/bin/bash
# file: index.sh
octave -qH --eval "
indexes = [$1]  ;
indexes = reshape(indexes,2,[])'  ;
count = 1 ;
for R = 1:rows(indexes)
  for C = 1:indexes(R,1)
    printf('%d ' , count:count+indexes(R,2)-1)
    printf('\n')
    count+=indexes(R,2) ;
  end
end
"

This can for for example be called like this:

$ ./index.sh "2 3 1 6 1 2"

1 2 3
4 5 6
7 8 9 10 11 12
13 14

to be processed further in the surrounding shell-script.

Very cool, thank you.
Stefan


Yo are very welcome. :-)

--
DAS

https://linuxcounter.net/user/206392.html

reply via email to

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