how to append "specific columns" in an array

hello ,
i tried so many combinations of codes using reshape and permute function but i couldn't get the desired output
suppose my array looks like
0 0
0 0
1 1
0 1
there are 2 columns and i want to take 1st column and copy it in 2nd and 3rd column , but i want to append it , i dont want to overwrite existing columns
so as a result i want 6 columns
0 0 0 0 0 0
0 0 0 0 0 0
1 1 1 1 1 1
0 0 0 1 1 1
i tried 2 clear my problem .... Can AnyOne Help With This Please??
I am Looking for Generalized code that can work for every array

2 comentarios

Mischa Kim
Mischa Kim el 20 de Mzo. de 2014
Is the very first column supposed to be [0;0;1;0] rather than [0;0;0;0]?
pooja
pooja el 20 de Mzo. de 2014
sorry i edited the mistake ...does it look ok now ?

Iniciar sesión para comentar.

 Respuesta aceptada

Mischa Kim
Mischa Kim el 20 de Mzo. de 2014
Editada: Mischa Kim el 20 de Mzo. de 2014
Pooja, use
B = reshape(repmat(A,3,1),length(A(:,1)),[])
assuming the first column is (supposed to be, typo?) equal to the second one in the 12-column matrix.

4 comentarios

pooja
pooja el 20 de Mzo. de 2014
Oh thank you so much Mr. Mischa Kim
i am a beginner in maatlab and these 2 (reshape and permute) are still a mystery 2 me :P
pooja
pooja el 20 de Mzo. de 2014
Can i get generalized code ?
this works with only this specific array
sorry i didn't specified it !!
Mischa Kim
Mischa Kim el 20 de Mzo. de 2014
See above. What else do you need to generalize? The number of repeated columns?
pooja
pooja el 20 de Mzo. de 2014
oh now it works all fine....thank you so much Mr.Mischa Kim :)

Iniciar sesión para comentar.

Más respuestas (1)

Chandrasekhar
Chandrasekhar el 20 de Mzo. de 2014
A = [0 0 0 0;0 0 1 0;1 1 1 1;0 1 0 1];
appending 1st column of A at the end|
A = [A A(:,1)];

1 comentario

pooja
pooja el 20 de Mzo. de 2014
Though its not i was looking for ,Thank you for replying :)

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

el 20 de Mzo. de 2014

Comentada:

el 20 de Mzo. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by