Separate all data from table by date

조회 수: 6 (최근 30일)
Debbie Oomen
Debbie Oomen 2018년 5월 1일
댓글: Peter Perkins 2018년 5월 14일
Hi everyone!
I need to separate data in a table based on their dates. I cannot seem to figure out the code for this. I have found several options such as datenum and timetable. The datenum option gives me an error because the dates are not a string and datestr does not function either. The dates are displayed in the following format : DD/MM/YYYY. I have also tried converting the table to a structure but this just displays the date as: 1x1 datetime
  댓글 수: 2
Ameer Hamza
Ameer Hamza 2018년 5월 1일
Can you show an example of your table content, or better yet if you could share a sample mat file, which could contain the table data.
Debbie Oomen
Debbie Oomen 2018년 5월 1일
This is the table content. Thanks for the help

댓글을 달려면 로그인하십시오.

채택된 답변

Ameer Hamza
Ameer Hamza 2018년 5월 1일
One possible solution is to use splitapply(). It will split your table into several tables based on dates
splitapply(@(x) {x}, myTable{:,:}, findgroups(myTable{:, 1}))
this supposes that dates are present in the first column of the table myTable.
  댓글 수: 5
Debbie Oomen
Debbie Oomen 2018년 5월 2일
I need to analyse one cell of each date and save this per day. What would be the best/easiest way to do this?
Ameer Hamza
Ameer Hamza 2018년 5월 2일
Does it depend on what you want to analyze? cellfun() might be an option since it can apply a function on every cell in a cell array and save the output in a variable.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Peter Perkins
Peter Perkins 2018년 5월 2일
Debbie, Ameer's solution answers your question, but you should ask yourself why you want to split your data up. There are lots of things you can do by applying functions to groups of data while they are still within a table. In fact, findgroups/splitapply is one of the ways to do that.
Very often, you are better off leaving the data all in one container.
  댓글 수: 2
Debbie Oomen
Debbie Oomen 2018년 5월 4일
Thank you Peter, but how would I do this? I have a file with an amount of data for 10 days and want to get data from each individual day.
Peter Perkins
Peter Perkins 2018년 5월 14일
I don't know what you mean by "get". If your goal is to split up the data, then you should do that, and Ameer's sol'n works. But I am suggesting that your goal is probably more like "find the mean temperature for each day", and you don't need to split up your data to do that.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by