How can i filter data using time frames?

Hi,
I got a table with 2 colums. In the first is the time in datetime and in the second colum is data associated with the time. I have data for each our of each day for multiple years and I want to calculate the mean of the data for a given year.
How can I access my data in relation to the time and select that i just want the data of a given year?

7 件のコメント

Star Strider
Star Strider 2020 年 5 月 27 日
See if the retime function will do what you want.
Image Analyst
Image Analyst 2020 年 5 月 27 日
Make it easy for people to help you by attaching your table in a .mat file with the paper clip icon.
Julozert
Julozert 2020 年 5 月 27 日
No retime doesnt help what i want to do.
I want to specify the year use just this year but it doesnt seem to work. Here what i thought could work but it didnt,
How can i get the data out of the table by just asking for the time?
year=1990;
time1=datetime(year,01,1,1,0,0);
time2=datetime(year,31,12,23,0,0);
z=0;
for c=time1:time2
temp=temp+T(c,2);
z=z+1
end
mean=temp/z;
Star Strider
Star Strider 2020 年 5 月 27 日
Convert your data (table) to a timetable as the documentation states. Use retime with the timetable.
Julozert
Julozert 2020 年 5 月 27 日
I converted the time into datetime. I hope the table helps, i feel pretty helpless rn
Eric Sofen
Eric Sofen 2020 年 6 月 9 日
If you want to do the calculation one-year-at-a-time rather than calculating averages for all years, you can use the timerange method on your timetable to select all values within the specified year, then calculate the average of the corresponding data variable.
Adam Danz
Adam Danz 2020 年 6 月 9 日
In order to see your data we need to
  1. Download the file
  2. unzip the file
  3. read in the data
  4. convert to datetime
and at any point, we may do something differently than you did so our result might not work with your style of reading in and formatting the data. Reduce the amount of work we need to do before we can start helping you by either reproducing a small sample of your table that we can copy-paste into our systems or supply your code that we can apply to your data.
I agree with Start that a timetable is most appropriate and that retime would be simple to apply once your data are in a timetable.
You can probably read in the data using readtable() then convert to a timetable using table2timetable(). Then you can apply retime().

サインインしてコメントする。

回答 (0 件)

カテゴリ

製品

リリース

R2020a

質問済み:

2020 年 5 月 27 日

コメント済み:

2020 年 6 月 9 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by