How to stretch matrix

조회 수: 9 (최근 30일)
Yu-Jou Pai
Yu-Jou Pai 2019년 8월 1일
답변: Akira Agata 2019년 8월 1일
I am wondering if there is a way to do so...
Suppose I have a 1 x 5 matrix that contains 5 random numbers, x=[2,10,31,24,11]
Now, I would like to make it become y=[2,3,10,11,31,32,24,25,11,12]
that is, add a column next to each column in z, and each of the additional column added carries the value that is +1 of z's value.

채택된 답변

Walter Roberson
Walter Roberson 2019년 8월 1일
y = reshape( [x; x+1], [], 1);
  댓글 수: 1
Yu-Jou Pai
Yu-Jou Pai 2019년 8월 1일
Thank you

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

추가 답변 (1개)

Akira Agata
Akira Agata 2019년 8월 1일
Not so sophisticated, but intuitively clear way:
y = repelem(x,2);
y(2:2:end) = y(2:2:end)+1;

태그

Community Treasure Hunt

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

Start Hunting!

Translated by