help-octave
[Top][All Lists]
Advanced

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

Re: arbitrary rotating values of an array


From: Rick T
Subject: Re: arbitrary rotating values of an array
Date: Mon, 9 Jan 2012 19:23:14 -1000

Thanks

in case someone wanted to see working code

%permute array

clear all,clc

array=[11,22,33,44,55]

cycle_permute_rt = @(array, k) [array(mod((1:end)-k-1, end)+1 )]

aa=[];

bb=[];

for ii=0:1:4

a=cycle_permute_rt(array, ii)

aa=[aa;a]

end;

for ii=0:-1:-4

b=cycle_permute_rt(array, ii)

bb=[bb;b]

end;



2012/1/9 Jordi Gutiérrez Hermoso <address@hidden>
On 9 January 2012 22:51, Rick T <address@hidden> wrote:
>
> Greetings All
>
> I'm trying to arbitrarily rotate the values of an array but the rot commands
> don't seem to work for me.
>
> Example
> array=[1,2,3,4,5]
> I would like the array to be placed in a for loop so it steps through each
> iteration
> iteration1 of array=[2,3,4,5,1]
> iteration2 of array=[3,4,5,1,2]
> iteration3 of array=[4,5,1,2,3]
> iteration4 of array=[5,1,2,3,4]

This sounds like an X-Y problem:

   http://www.perlmonks.org/index.pl?node_id=542341

Regardless, it's simple to do:

   cycle_permute = @(array, k) [array(k+1, end), array(1:k)]
   cycle_permute(array, 1)
   cycle_permute(array, 2)

etc

- Jordi G. H.



--


reply via email to

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