Replicating values a certain number of times
Show older comments
Hello, I have a long array of data from 0 to 1959 in steps of 1. Is there any way to expand that data so that each value repeats x number of times? ie. if x is 4
new = 0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3...
I have compressed data and I want to be able to expand it with this approximation.
Thanks for your help!
Accepted Answer
More Answers (2)
try this:
x = 1:100; % Values to be repeated
a = 4; % Number of times each value is repeated
b = repmat(x, 4);
b = reshape(b, 1, []); % Final result
Andrei Bobrov
on 3 Dec 2013
Jos (10584)'s idea:
k = 1959;
n = 4;
x = floor((0:(k+1)*n-1)/n);
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!