How can I generate an array that satisfies a given number of repetitions and unique values
Show older comments
I have a repetition vector x = [3 2 1 2] and set of unique values y = [1 2 3 4]; How can I generate a vector z such that x = histc(z,y);
In this case z would be [1 1 1 2 2 3 4 4]
Thanks in advance!
KL
Accepted Answer
More Answers (1)
Roger Stafford
on 19 Aug 2013
t = accumarray(cumsum([1,x]),1);
z = y(cumsum(t(1:end-1)));
Categories
Find more on Histograms 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!