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: Jordi Gutiérrez Hermoso
Subject: Re: arbitrary rotating values of an array
Date: Tue, 10 Jan 2012 00:58:26 -0500

On 10 January 2012 00:23, Rick T <address@hidden> wrote:
> 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;

I was wondering if that was what you wanted. This can be accomplished
with broadcasting:

    aa = bsxfun(@circshift, array', 0:4)';
    bb = bsxfun(@circshift, array', 5:-1:1);

- Jordi G.H.


reply via email to

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