if option with weekend and date serial number

2 visualizaciones (últimos 30 días)
AA
AA el 28 de Nov. de 2017
Respondida: Walter Roberson el 28 de Nov. de 2017
I have a date serial number x. If the number is a weekend then x+3, if the number is not a weekend then x +1. how can i put this as code?

Respuesta aceptada

Walter Roberson
Walter Roberson el 28 de Nov. de 2017
output = x + 1 + 2 * isweekend( datetime(x, 'convertfrom', 'datenum') );
or
output = x + 1 + 2 * ismember(weekday(x), [1 7]);

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by