How to convert day information to a number?

1 visualización (últimos 30 días)
John Lee
John Lee el 24 de Sept. de 2021
Comentada: Star Strider el 24 de Sept. de 2021
How can I convert day information to a number?
For instance, Mon to 1, Tue to 2, etc.
Fo from character to number data.

Respuesta aceptada

Star Strider
Star Strider el 24 de Sept. de 2021
Experiment with something like this —
daynr = @(x) find(strcmp(x, {'Mon','Tue','Wed','Thu','Fri','Sat','sun'}));
nr = daynr('Thu')
nr = 4
Everything depends on the context it will be used in, so this is just an example of one approach.
.
  2 comentarios
John Lee
John Lee el 24 de Sept. de 2021
Oh, this is what I wanted, thanks. I modified your answer with a 100-by-1 column string vector (i.e. "day" variable)
%%
clear
load day % 100-by-1 string data
daynr = @(x) find(strcmp(x, {'Mon','Tue','Wed','Thu','Fri','Sat','Sun'}));
for i=1:length(day)
nr(i) = daynr(day(i));
end
Star Strider
Star Strider el 24 de Sept. de 2021
As always, my pleasure!
.

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by