Is there a way to extract dynamic values of timeseries without hardcoding?

조회 수: 3 (최근 30일)
nines
nines 2022년 10월 21일
댓글: nines 2022년 10월 21일
I have a multiple timeseries that goe as follows:
Subject 1 (13x1):
1
1
1
2
2
2
5
5
5
5
8
8
8
Subject 2:
1
1
1
4
4
4
4
4
7
7
9
9
9
9
9
9
I want to calculate the difference between every change and the first value (1), and then I also want to caclualte the difference between the multiple conditions (e.g. 7-4=3, 5-2=3, etc). For one subject, I could hard code the section of the timeseries as follows and do as follows:
Example for subject 1:
timeseries(11)-timeseries(2)=6
Example for subject 2:
timeseries(4)-timeseries(1)=3
Is there a way to do this without hardcoding the part of the timeseries?
Thanks a ton
  댓글 수: 2
Matt
Matt 2022년 10월 21일
The function unique (https://fr.mathworks.com/help/matlab/ref/double.unique.html) can help you do that.
C = unique(timeserie);
C-timeserie(1)% this is the difference between all the multiples elements and the first element
if you want the difference between all the uniques elements you can do a loop on the elements of C to compute all the possible variations. Something like this :
for ii=1:length(C)
for jj=1:length(C)
diff(ii,jj) = C(ii)-C(jj);
end
end

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Time Series에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by