time series and grouping

7 views (last 30 days)
akk
akk on 19 Oct 2020
Answered: Eric Sofen on 12 Nov 2020
Hello,
I have a table with multiple sites (SITE_ID) and temperature time series associated with each site. Each site has a lat, lon and depth as well. I would like to group the data by SITE_ID, and then plot the tempearature time series associated with each site. TIMESTAMP is a string and TEMP_C is a double.
I know the first step is to group:
[G,ID]=findgroups(SITE_ID)
but am not sure how to plot associated time series for each unique site
Thank you!

Answers (1)

Eric Sofen
Eric Sofen on 12 Nov 2020
It's tough to give a detailed answer without seeing the structure of your data and preliminary code, but here are a few suggestions:
1) Convert your TIMESTAMPs to datetime.
2) You could use varfun to plot, using SITE_ID as a grouping variable. Something like
p = varfun(@(dt,temp) plot(dt,temp), t, 'InputVariables',{'TIMESTAMP','TEMP_C'},'GroupingVariables','SITE_ID')
It will actually return a table with the line objects for the charts. If you use hold on, you can get all the plots on one chart.
3) If you want subplots, you're right that you're probably better off iterating over the unique values of SITE_ID.

Categories

Find more on Time Series 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!