Group values in a vector
4 views (last 30 days)
Show older comments
Hi,
I have a long column vector ('trialnr', attached), whose elements are integer numbers from 1 to 55 (they index events in time-series).
I want to further concetenate the elements into groups (1-2, 3-4, 5-6, etc) so that I create blocks of rest-movement. The new vector will have the same size as the original.
Therefore, I want 1-2 to be 1, 3-4 to be 2 and so forth.
Any help would be great, thank you!
for example: if length(trialnr(trialnr==1)) is 7765 and length(trialnr(trialnr==2)) is 3548, then in the column vector these will be designated as 1 with length 7765+13548=11313.
1 Comment
Star Strider
on 26 Jun 2023
I don’t see how this is going to work, since the ranges of the various elements (numbers of the individual elements) in the vector, although consecutive, are different —
LD = load('trialnr');
trialnr = LD.trialnr;
[Elements,Startidx,ic] = unique(trialnr, 'stable');
Lengths = diff([Startidx; size(trialnr,1)]);
LenvTable = table(Elements,Startidx,Lengths)
.
Accepted Answer
DGM
on 26 Jun 2023
I'm not sure if this is what you're asking for, but:
V = [1 1 1 2 2 2 3 3 3 4 4 4 5 5 5]
V = ceil(V/2)
More Answers (0)
See Also
Categories
Find more on Lighting, Transparency, and Shading 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!