array manipulation - a few basic questions

Hi, I have to do a bit of array manipulation and I really don't have a clue about it.
First I need to know how to take a double array, and turn it in to a 2046x1 array (twice as long), with 1024-2046 just being exactly the same as 1-1023.
Then I need to know how to chop off the first half of an array, in this case taking a 2046x1 array and disregarding the first 1-1023, leaving only a 1023x1 array made up from only the second half of the 2046x1 array.
I know it's simple stuff, but I just haven't done it before.

1 comentario

Matt Fig
Matt Fig el 2 de Nov. de 2012
Tom's question
Hi, I have to do a bit of array manipulation and I really don't have a clue about it.
First I need to know how to take a double array, and turn it in to a 2046x1 array (twice as long), with 1024-2046 just being exactly the same as 1-1023.
Then I need to know how to chop off the first half of an array, in this case taking a 2046x1 array and disregarding the first 1-1023, leaving only a 1023x1 array made up from only the second half of the 2046x1 array.
I know it's simple stuff, but I just haven't done it before.

Iniciar sesión para comentar.

 Respuesta aceptada

Rick Rosson
Rick Rosson el 19 de Mzo. de 2012
Please try:
x = rand(1023,1);
y = repmat(x,2,1);
z = y(1024:2046);
HTH.
Rick

6 comentarios

Jan
Jan el 19 de Mzo. de 2012
Or: y = [x; x];
or: y = vertcat(x, x);
Rick Rosson
Rick Rosson el 19 de Mzo. de 2012
Or: z = y(1024:end);
Jan
Jan el 19 de Mzo. de 2012
I avoid the END in indexing expressions in general. There have been several bugs in nested expressions and it is "slower" than "1024:numel(y)" - if one could claim that micro-seconds matter.
Tom
Tom el 19 de Mzo. de 2012
Many thanks guys - all useful.
Tom
Tom el 19 de Mzo. de 2012
I guessed that z = y(numel(x)+1:numel(y)); would work too. That make sense?
Rick Rosson
Rick Rosson el 19 de Mzo. de 2012
Yes, at least in this particular case, but not generally.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Productos

Etiquetas

Preguntada:

Tom
el 18 de Mzo. de 2012

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by