Group values in a vector

4 ビュー (過去 30 日間)
Panos Kerezoudis
Panos Kerezoudis 2023 年 6 月 26 日
コメント済み: Panos Kerezoudis 2023 年 7 月 1 日
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 件のコメント
Star Strider
Star Strider 2023 年 6 月 26 日
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)
LenvTable = 55×3 table
Elements Startidx Lengths ________ ________ _______ 1 1 7765 2 7766 3548 3 11314 4224 4 15538 4710 5 20248 3772 6 24020 1808 7 25828 1881 8 27709 1114 9 28823 2756 10 31579 1066 11 32645 2805 12 35450 1065 13 36515 3240 14 39755 1162 15 40917 1874 16 42791 1517
.

サインインしてコメントする。

採用された回答

DGM
DGM 2023 年 6 月 26 日
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 = 1×15
1 1 1 2 2 2 3 3 3 4 4 4 5 5 5
V = ceil(V/2)
V = 1×15
1 1 1 1 1 1 2 2 2 2 2 2 3 3 3
  1 件のコメント
Panos Kerezoudis
Panos Kerezoudis 2023 年 7 月 1 日
that works great, thank you so much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by