Creating a matrix with repeating the same numbers.

Hi, i am back with one more question.
If 't' is any variable, let's keep t=10
i need a matrix
A=[1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11]
if t=11, i need
A=[1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12]
Any help will be appreciated. this is because of my project.

 채택된 답변

dpb
dpb 2014년 10월 28일
편집: dpb 2014년 10월 29일
Not a lot of work there...
v=repmat([2:t],2,1);
A=[1 v(:).' t+1];

댓글 수: 4

i received this error.
">> v=repmat([2:t],2,1); A=[1 v(:) t+1].'; Error using horzcat Dimensions of matrices being concatenated are not consistent."
Thanks for your effort. any help will be appreciated.
dpb
dpb 2014년 10월 29일
편집: dpb 2014년 10월 29일
misplaced the .' as (:) returns column vector...amended.
dpb
dpb 2014년 11월 2일
Looks like Roger S was already by...

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

질문:

2014년 10월 28일

댓글:

dpb
2014년 11월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by