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: stn
Subject: Re: Efficient definition of multidimensional ranges
Date: Sat, 9 Jun 2012 02:41:21 +0200


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


reply via email to

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