How to arrange month columns based on date code is run?

1 Ansicht (letzte 30 Tage)
ComplexCosines
ComplexCosines am 26 Mär. 2020
Kommentiert: ComplexCosines am 27 Mär. 2020
I have a slection of code that runs monthly, adding counter data. Now we are in a new year it does not organise this in a readable format.
Table below is how it currently returns the data if run in March.
Table =
1×13 table
Items zJan zFeb zMar zApr zMay zJun zJul zAug zSep zOct zNov zDec
______ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____
"Item" 1000 1100 1200 100 200 300 400 500 600 700 800 900
What would allow me to rearrange automatically based on the date the code was run to give the below table?
TableTwo =
1×13 table
Items zApr zMay zJun zJul zAug zSep zOct zNov zDec zJan zFeb zMar
______ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____ ____
"Item" 100 200 300 400 500 600 700 800 900 1000 1100 1200

Akzeptierte Antwort

dpb
dpb am 26 Mär. 2020
vnames=month(datetime(1,[1:12],1),'short'); % return dummy variable names containing short month names
% engine
>> circshift(vnames,-find(contains(vnames,split(date,'-'))))
ans =
1×12 cell array
{'Apr'} {'May'} {'Jun'} {'Jul'} {'Aug'} {'Sep'} {'Oct'} {'Nov'} {'Dec'} {'Jan'} {'Feb'} {'Mar'}
>>
Circularly shift the variables in the right direction by desired amount based on current month from present date...

Weitere Antworten (0)

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by