change calculation into financial/fiscal year

1 次查看(过去 30 天)
I've been doing my calculations/written my code based on calendar year, but realised now that I should have done it based on financial year i.e. 1st April to 31st March. Is there an simpler way to do this without having to change a lot of the lines. To simplify, say I have 2 matrices:
Power = [year month day hour data1]
Speed = [year month day hour data2]
I've changed the year month day into timestamp using datenum and match the timestamp of Power and Speed to give a relative magnitude of wind speed to power:
Power curve = [year month data2 data1]
In a lot of my subsequent calculations, I've done a lot of loops based on calendar year using 'unique year' and therefore it would be a pain to change a lot of that. Just to give you an idea, I have hourly Power data for 17 power stations, each with varying year of operations, and hourly speed data from 1985-2018.
So my question is, is there a way to manipulate my initial data (Power and Speed) so that the 'unique year' corresponds to 1st April to 31st March, rather than 1st Jan to 31st Dec?
Thanks!
  6 个评论
dpb
dpb 2018-6-28
We're fortunate that they are still (at least so far) on the far horizon but they're some of the newer monsters and it's almost 60 mi away and they're still on the horizon from the second floor window.
I can't imagine the problem when they're right in the neighborhood, especially if it's your neighbor getting the royalty check and all you have is the noise and visual pollution.
It's one of these things that is much better in theory and for some than others in practice.

请先登录,再进行评论。

采纳的回答

dpb
dpb 2018-6-26
编辑:dpb 2018-6-26
Actually, it's pretty simple to accomplish. Given the year and month vectors, create a "financial year" by
yrFin=yr; % initialize to existing year
ix=(mo<4); % logical index to Jan-Mar
yrFin(ix)=yr(ix)-1; % belongs to previous financial year
I would still recommend looking seriously at datetime instead of datenum and in particular then investigate the use splitarray, varfun and findgroups to simplify the computations by groups where here for starters the grouping variable would by yrFin
Also NB: that the names year, month, etc., are Matlab builtin functions used with datetime class so I've not used those as variables.
  2 个评论
NMans
NMans 2018-6-27
Thanks dpb - this works very well but for incomplete data (less than a year), it means that the data is merged into the year before. I just have to delete incomplete data so it doesn't affect the year before.
dpb
dpb 2018-6-28
编辑:dpb 2018-6-30
Having hard time envisioning what wouldn't still be the correct analysis year; by your definition anything in the first Q is the previous year.
Show an example that you think is a problem...
ADDENDUM
Or, of course, you could alternatively define the analysis year to be the same as the actual year of the Q1 dates in which case the remainder is in the next analysis year and then one would write that
yrFin=yr; % initialize to existing year
ix=(mo>3); % logical index to Jan-Mar
yrFin(ix)=yr(ix)+1;
It's totally arbitrary as to which you choose.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Calendar 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by