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

4 次查看(过去 30 天)
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