how to obtain values using a key in another table?
Mostra commenti meno recenti
I have a bit of a problem so I have my data like this:
date Concentration.
'4/13/1994' 8
'4/14/1994' 8.5
'4/15/1994' 8.3
'4/16/1994' 7.9
'4/17/1994' 8
'4/18/1994' 9.5
'4/19/1994' 9.6
'4/20/1994' 9.1
'4/21/1994' 9
'4/22/1994' 9.6
and another table with key dates data
'4/15/1994'
'4/21/1994'
what would you recommend for me to use so that i can read the dates in the first column using the second column as a key, and get an average of the data between these two dates.
I would really appreacite your recommendations.
Best
2 Commenti
What output do you want? The average concentration between 4/15/1994 and 4/21/1994 (bounds included?) or something else?
What if the key date table has more than two rows. Is the window between each consecutive row, or is it between each two pairs of consecutive rows, e.g with:
keydates
4/15/1994
4/21/1994
4/28/1994
5/02/1994
are the windows 15:21, 21:28, 28:02 or are they just 15:21, 28:02 ?
Also can you confirm that your dates are stored as datetime?
Esteban Tamayo
il 25 Set 2019
Risposte (1)
Guillaume
il 25 Set 2019
First, convert the date strings into proper dates. However you imported that data, you should be able to import it directly as datetime.
After the fact,
yourtable.Date = datetime(yourtable.Date, 'InputFormat', 'M/d/yyyy') %taking a guess at your format.
Then, convert the concenration table to timetable (in recent versions of matlab you could import directly as timetable)
tt_concentration = table2timetable(yourconcentrationtable);
Then retime it according to the time vector specified in the key date table. (the dates must be uniques, ordered, and converted to datetime):
concentration_keydates = retime(tt_concentration, keydates.Date, 'mean')
2 Commenti
Esteban Tamayo
il 25 Set 2019
Steven Lord
il 25 Set 2019
The timerange function may also be of use to you in extracting data from your timetable.
Categorie
Scopri di più su Time Series Objects in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!