MATLAB Answers

How to stretch matrix

17 views (last 30 days)
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.

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 1 Aug 2019
y = reshape( [x; x+1], [], 1);

  1 Comment

Yu-Jou Pai
Yu-Jou Pai on 1 Aug 2019
Thank you

Sign in to comment.

More Answers (1)

Akira Agata
Akira Agata on 1 Aug 2019
Not so sophisticated, but intuitively clear way:
y = repelem(x,2);
y(2:2:end) = y(2:2:end)+1;

  0 Comments

Sign in to comment.

Tags