Grouping data into bins and then plotting them

Hello, I am trying to read some tables into matlab, the tables contain the variable 'hour' to represent the time when the data accurued. after reading the tables we would like to bin the data in the table according to the 'hour' variable and then plot the data to see how they are changing.
for example: we would like to see how the data is changing every three hours in the day, so from all the data set we have we would like to group the data of the first three hours and then plot them and see and so on for the rest of 24hrs. How can we possibly implement that?

 Accepted Answer

You can calculate the every three hours mean using the fuction retime. Read about it. To see the variation of every hours, striaght aways you can use plot.

10 Comments

thanks for the quick reply, but my issue is how to get to the data of the 1st three hours for example. given that its a huge data set (>400 files) of tables and each table represents data of different hours of the day.Furthermore, we are more intrested in plotting the data itself rather than just the mean as there are other factors affecting it.
so how can I go through the tables to get to the data for 1st three hours then the 2nd three hours and so on then plotting them? I have started with if loop but I am not sure if that would be the best technique to ues.
Attach one sample file. It depends on ow the hours data is given.
Is all of the data of all of the tables to be lumped together as if it had been from one source?
Or is each table to be done individually?
Consider using findgroups() and splitapply()
in the attached file we have the hours are between 20 and 22 and that would be the last time interval of the day. assuming that we want the data to be in the intervals: 0-3, 4-7, 8-11, 12-15, 16-19, 20-23. getting the data for each of these intervals from all the tables we have and plot it.
Read all the text files into a single table and use histogram.
@Walter Roberson its not neccesary to have each table done indiviually as we are intreseted in intervals of time from all the tables, we can cosider it as it is all from one source.
The attached table has only two hours 20 and 22.
T = readtable(file) ;
You can access the hour column by T.HOUR or T.(4).
I understand that histogram would allow me to sort my data into bins and plot them easily. but would there be another way rather than histogram to plot the data? as bars and rectangles would not be the best visualization of our data, we would like to represnet them as a dot for each row.
Using historgram helps you to split the data into intervals, get the indices of the intervel bins and then use these indices to plot using in your required way.
Thank you for the help, you gave me a much more effecient way to deal with my data. really apperciate it.

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2021b

Asked:

on 17 Oct 2021

Commented:

on 17 Oct 2021

Community Treasure Hunt

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

Start Hunting!