how to select range of dates

조회 수: 4 (최근 30일)
rohail khan
rohail khan 2018년 4월 11일
댓글: Peter Perkins 2018년 4월 13일
I have stock data of 10 years with two columns.One is the stocks which is numeric and the other is dates which are in datetime format.I converted datetime to Numeric also. I want to calculate mean for each year using mean(stock) formula. But I dont know how can I select the data for each year separately? The days are also not continuous as there are holiday gaps How can I get the range of data for one year e.g like from jan 1 ,2007 to dec 31 2007 and then get its mean

채택된 답변

per isakson
per isakson 2018년 4월 11일
편집: per isakson 2018년 4월 11일
Hint:
accumarray( t.Year-2007+1, stock, [], @mean )
where t is a datetime object
  댓글 수: 2
rohail khan
rohail khan 2018년 4월 12일
thank you so much.You are amazing
Peter Perkins
Peter Perkins 2018년 4월 13일
There are any number of ways to do this. accumarray is old school. full(sparse(...)) would have been even older school. More beginner-friendly ways include findgroups/splitapply, and varfun with a grouping variable. And in R2018a, groupsummary.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by