How to calculate an average value in a matrix with respect to timestamps
6 views (last 30 days)
Show older comments
Eivind Sommerstad
on 10 Apr 2023
Commented: Eivind Sommerstad
on 13 Apr 2023
Hello, i have a "mixed Rinex observation" file that i have read into matlab with the "rinexread()" function. What i want to do is "group" the "SIC" values by the "Time" values so that for example all the values for SIC in the timestamp 13:49:10 gets added together, averaged out and then saved to a new matrix. I want this to happen for every "new" timestamp going down this file. For clarification, this is for the GPS part of the observation file.
1 Comment
Accepted Answer
Vinayak Choyyan
on 12 Apr 2023
Hi Eivind,
As per my understanding, you would like to sum ‘S1C’ data after grouping it by time.
Please check out the below example.
filename = "GODS00USA_R_20211750000_01H_30S_MO.rnx";
data = rinexread(filename);
tmp=data.GPS(:,9);
tmp=groupsummary(tmp,'Time','sum');
output=tmp(:,[1 3])
Since ‘data.GPS’ is of type ‘timetable’, we can use the ‘groupsummary’ function to find the sum of data after grouping it by column ‘Time’.
Note: In the above code, ‘S1C’ is the 9th column in ‘data.GPS’. The file "GODS00USA_R_20211750000_01H_30S_MO.rnx" is included with MATLAB and you can directly access it like I did in the above example.
For more details, please visit these documentation pages:
- ‘timetable’ https://www.mathworks.com/help/matlab/ref/timetable.html
- ‘groupsummary’ https://www.mathworks.com/help/matlab/ref/double.groupsummary.html
- How to sum over grouped data in a table https://www.mathworks.com/matlabcentral/answers/447189-how-to-sum-over-grouped-data-in-a-table
I hope this helps resolve the issue you were facing.
More Answers (0)
See Also
Categories
Find more on Data Import and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!