MATLAB Answers

Repeat matrix columns in pairs.

3 views (last 30 days)
Hello,
I'm trying to use the repelem function to repeat some columns of a matrix A like:
A = [1 2 3 4; 5 6 7 8];
If I use the repelem function I'll get the following output:
out = repelem(A,1,2);
out =
[1 1 2 2 3 3 4 4 ; 5 5 6 6 7 7 8 8]
However I'm trying to repeat two columns at the same time instead of doing it individually. So that I get an output like:
Output = [1 2 1 2 3 4 3 4; 5 6 5 6 7 8 7 8]
Anyone can come around a solution to this problem?
Thank you,
Santos

Accepted Answer

David Hill
David Hill on 22 Apr 2021
out=[repmat(A(:,1:2),1,2),repmat(A(:,3:4),1,2)];
  5 Comments
Santos García Rosado
Santos García Rosado on 23 Apr 2021
I'll take a good look at it. Thank you David.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by