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

2 vues (au cours des 30 derniers jours)
ComplexCosines
ComplexCosines le 26 Mar 2020
Commenté : ComplexCosines le 27 Mar 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

Réponse acceptée

dpb
dpb le 26 Mar 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...

Plus de réponses (0)

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by