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

2 visualizaciones (últimos 30 días)
ComplexCosines
ComplexCosines el 26 de Mzo. de 2020
Comentada: ComplexCosines el 27 de Mzo. de 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

Respuesta aceptada

dpb
dpb el 26 de Mzo. de 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...

Más respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by