Borrar filtros
Borrar filtros

Working with Dates,Problem with syntax

2 visualizaciones (últimos 30 días)
Aditya
Aditya el 12 de En. de 2014
Comentada: Aditya el 13 de En. de 2014
I have a set of dates stored in b array as 'dd-mm-yyyy' as strings. I need to write queries to select dates of a particular month. So I tried doing this:
for i=2:8400
index=strfind(b,'01');
end;
for i=2:8400
if(index(i)==3)
disp(b(i));
end;
end;
But it says '??? Undefined function or method 'eq' for input arguments of type 'cell'.' I new to matlab so I'm sorry if I'm doing something stupid. Thanks.

Respuesta aceptada

Amit
Amit el 12 de En. de 2014
Following your code trend: strfind might not work in this case as for example if you are looking for January (01) in a date string like 01-01-2013, there are 3 instances where 01 can be found. If the format dd-mm-yyyy is consistent in all your data, something like this might work:
b_tmp = b(:,[4 5]);
for i = 2:8400
if strcmp(b_tmp(i),'01') % Lets say you're looking for January (01)
disp(b(i));
end
end
  1 comentario
Aditya
Aditya el 13 de En. de 2014
Thanks Amit,
The solution worked.Just wanted to know how to check for a particular substring in a string,as in,finding '-01-' in '01-01-2013' using strcmp.
Regards.

Iniciar sesión para comentar.

Más respuestas (1)

Azzi Abdelmalek
Azzi Abdelmalek el 12 de En. de 2014
Example
s={'01-01-2013';
'11-01-2013'
'21-01-2013'
'22-03-2013'
'01-04-2013'
'21-05-2013'}
d=datevec(s,'dd-mm-yyyy');
% To search th month 01;
idx=d(:,2)==1
out=s(idx)

Categorías

Más información sobre String Parsing 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