Addition of time series' values in array
조회 수: 3 (최근 30일)
이전 댓글 표시
Hello,
I have a tricky one I haven't been able to solve. I have an array of objects of a specific class. One of the properties of this class is a time series. I can guarantee that all the time series for that particular property for all objects in the array have exactly the same time vector. I would like to sum all the values of that property (i.e. of those time series) into a single time series with the same time vector.
For example, I have an array OBJECTS composed of objects of class OBJ with property PROP of type timeseries. I want to add all the data values of the PROP time series.
I tried the following:
sum(OBJECTS(:).PROP.Data)
but didn't work. I'm not sure about the OBJECTS(:) part, in particular the (:). I made several different tests, also playing with the dimension for sum (first or second) but without success.
Any ideas? Thanks in advance for any suggestion.
답변 (2개)
Laurens Bakker
2012년 3월 7일
Why not just use a for loop?
sum = zeros( size(OBJECTS(1).PROP.Data );
for obj=OBJECTS
sum = sum + obj.PROP.Data;
end
owr
2012년 3월 13일
The double level of "." indexing could cause an issue, but if it was just single level this trick might work:
>> foo(1).data = rand(5,1);
>> foo(2).data = rand(5,1);
>> foo(:).data
ans =
0.7577
0.7431
0.3922
0.6555
0.1712
ans =
0.7060
0.0318
0.2769
0.0462
0.0971
>> [foo(:).data]
ans =
0.7577 0.7060
0.7431 0.0318
0.3922 0.2769
0.6555 0.0462
0.1712 0.0971
>> sum([foo(:).data],2)
ans =
1.4638
0.7750
0.6692
0.7016
0.2683
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Descriptive Statistics에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!