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

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

댓글을 달려면 로그인하십시오.

 채택된 답변

Mischa Kim
Mischa Kim 2014년 3월 20일
편집: Mischa Kim 2014년 3월 20일

1 개 추천

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

pooja
pooja 2014년 3월 20일
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 2014년 3월 20일
Can i get generalized code ?
this works with only this specific array
sorry i didn't specified it !!
Mischa Kim
Mischa Kim 2014년 3월 20일
See above. What else do you need to generalize? The number of repeated columns?
pooja
pooja 2014년 3월 20일
oh now it works all fine....thank you so much Mr.Mischa Kim :)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Chandrasekhar
Chandrasekhar 2014년 3월 20일

0 개 추천

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

pooja
pooja 2014년 3월 20일
Though its not i was looking for ,Thank you for replying :)

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

질문:

2014년 3월 20일

댓글:

2014년 3월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by