Replicating values a certain number of times
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Muneer
le 3 Déc 2013
Réponse apportée : Andrei Bobrov
le 3 Déc 2013
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!
0 commentaires
Réponse acceptée
Wayne King
le 3 Déc 2013
Modifié(e) : Wayne King
le 3 Déc 2013
There are a number of ways to do this.
One way use a constant interpolator:
x = 0:9;
h = ones(4,1);
xnew = zeros(40,1);
xnew(1:4:end) = x;
y = filter(h,1,xnew);
Another way use repmat()
x = (0:9)';
x = (repmat(x,1,4))';
x = reshape(x,40,1);
0 commentaires
Plus de réponses (2)
Andrei Bobrov
le 3 Déc 2013
Jos (10584)'s idea:
k = 1959;
n = 4;
x = floor((0:(k+1)*n-1)/n);
0 commentaires
Voir également
Catégories
En savoir plus sur Text Data Preparation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!