Create new vector from data - Counts of element locations in vector
Show older comments
I have kind of a strange specific need for transforming my data to use in a script a colleague has sent me. I'm new to MATLAB, so changing my data should be easier than rearranging the guts of the code.
What I need is to change a vector of numbers (between 0 and 5) to a new vector with 'counts' of the location of the number in the original vector. That's confusing, so for an example:
x = [0,1,0,2,0,3,0,1,1,4]
would become:
y = [2,4,4,6,6,6,8,9,10,10,10,10]
Where the first '2' in y is the location of the '1' at the second location in vector x, etc.
Other than a subset of the find and sum functions, I'm stumped. Thanks in advance for any help, I'm still familiarizing myself with the software.
Accepted Answer
More Answers (0)
Categories
Find more on Data Types 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!