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: Sergei Steshenko
Subject: Re: Efficient definition of multidimensional ranges
Date: Fri, 8 Jun 2012 17:47:03 -0700 (PDT)





>________________________________
> From: stn <address@hidden>
>To: Doug Stewart <address@hidden> 
>Cc: help-octave <address@hidden> 
>Sent: Saturday, June 9, 2012 3:41 AM
>Subject: Re: Efficient definition of multidimensional ranges
> 
>
>
>
>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
>
>

I didn't go into details, bu what is the 'sh' language feature is absent in 
Octave interpreter which makes the shell script necessary ?


Thanks,
  Sergei.


reply via email to

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