Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Shifting inside a 1 dimension array ?

Subject: Shifting inside a 1 dimension array ?

From: DRG

Date: 10 Nov, 2010 20:26:44

Message: 1 of 3

If I have a 1 x 5 array, say

A = [2 3 5 7 11 ]

can i shift elements in it linearly by a step of, for example, 2, so
the array becomes

A = [7 11 2 3 5]

This should be easy to do and I fooled around with circshift abit but
it didnt really do what I wanted.

Very grateful if anyone could help!

Subject: Shifting inside a 1 dimension array ?

From: Walter Roberson

Date: 10 Nov, 2010 20:33:16

Message: 2 of 3

On 10-11-10 02:26 PM, DRG wrote:
> If I have a 1 x 5 array, say
>
> A = [2 3 5 7 11 ]
>
> can i shift elements in it linearly by a step of, for example, 2, so
> the array becomes
>
> A = [7 11 2 3 5]
>
> This should be easy to do and I fooled around with circshift abit but
> it didnt really do what I wanted.
>
> Very grateful if anyone could help!

 >> circshift([2 3 5 7 11 ].',2).'
ans =
      7 11 2 3 5

Subject: Shifting inside a 1 dimension array ?

From: Sean

Date: 10 Nov, 2010 20:36:04

Message: 3 of 3

DRG <grimesd2@gmail.com> wrote in message <a50f3420-251b-45f1-9696-98e8f228511a@t35g2000yqj.googlegroups.com>...
> If I have a 1 x 5 array, say
>
> A = [2 3 5 7 11 ]
>
> can i shift elements in it linearly by a step of, for example, 2, so
> the array becomes
>
> A = [7 11 2 3 5]
>
> This should be easy to do and I fooled around with circshift abit but
> it didnt really do what I wanted.
>
> Very grateful if anyone could help!

That's because
circshift(A,2)
is shifting the first dimension (rows) by 2. Since you only have one row, nothing changes.

You want to shift no rows and 2 columns, thus:\
circshift(A,[0 2])

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us