how to append "specific columns" in an array

조회 수: 2 (최근 30일)
pooja
pooja 2014년 3월 20일
댓글: pooja 2014년 3월 20일
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일
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
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일
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 :)

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by