필터 지우기
필터 지우기

Group values in a vector

조회 수: 1 (최근 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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by