Thread Subject: Interleave every 2 values

Subject: Interleave every 2 values

From: Sylvie

Date: 19 Feb, 2009 01:42:01

Message: 1 of 3

Hello,

s=[linspace(0,3,22)];

I would like to interleave every 2 numbers:
[s(1),s(3),s(2),s(4)...s(22)]

Any suggestion

Sylvie

Subject: Interleave every 2 values

From: Jos

Date: 19 Feb, 2009 08:43:02

Message: 2 of 3

"Sylvie " <sylpel@yorku.ca> wrote in message <gnidd9$232$1@fred.mathworks.com>...
> Hello,
>
> s=[linspace(0,3,22)];
>
> I would like to interleave every 2 numbers:
> [s(1),s(3),s(2),s(4)...s(22)]
>
> Any suggestion
>
> Sylvie

So you want numbers to repeat, as in [s1, s3, s2, s4, s3, s5, s4, s6 ... s22]

s = 1:8
s2 = reshape([s(1:end-2) ; s(3:end)],1,[])

If this is not what you want, try again ...

hth
Jos

Subject: Interleave every 2 values

From: us

Date: 19 Feb, 2009 09:15:04

Message: 3 of 3

"Sylvie"
> s=[linspace(0,3,22)];
> I would like to interleave every 2 numbers:
> [s(1),s(3),s(2),s(4)...s(22)]...

one of the many possible solutions

     s=1:16; % <- must be divisible by 4
     r=[s(1:2:end);s(2:2:end)];
     r=mat2cell(r,[1,1],repmat(2,1,numel(s)/4));
     r=cat(2,r{:})
% note: NO repeats...
% r = 1 3 2 4 5 7 6 8 9 11 10 12 13 15 14 16

us

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
code us 19 Feb, 2009 04:20:06
mat2cell us 19 Feb, 2009 04:20:06
repmat us 19 Feb, 2009 04:20:06
cat us 19 Feb, 2009 04:20:06
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com