필터 지우기
필터 지우기

change calculation into financial/fiscal year

조회 수: 5 (최근 30일)
NMans
NMans 2018년 6월 25일
편집: dpb 2018년 6월 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
NMans
NMans 2018년 6월 28일
Ah fair enough! Sorry to hear that..
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