MATLAB: Change calculation into financial/fiscal year

calendar yearsort

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!

Best Answer

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.