Timestamp not converting to a string

4 visualizaciones (últimos 30 días)
saadatnk8
saadatnk8 el 22 de Oct. de 2015
Comentada: dpb el 22 de Oct. de 2015
I imported data from excel which has timestamps, i.e. just time for example '7:01 PM' as a matlab number. However, I'm using the datestr() function to convert the matlab date number to a string and I am getting the following error.
Subscript indices must either be real positive integers or logicals.
Error in formatdate (line 158)
month = char(strrep(month(dtvector(:,2)), '.', '')); %remove period
Error in dateformverify (line 32)
S = char(formatdate([y,mo,d,h,minute,s],dateformstr,islocal));
Error in datestr (line 194)
S = dateformverify(dtnumber, dateformstr, islocal);
This is the code that I used
a = datestr(PM10data.Time);
However, if I use a specific value in the dataset, say a = datestr(PM10data.Time(391)) the code works. Please help me fix this.
I have attached the .mat file which has all the timestamps

Respuestas (1)

dpb
dpb el 22 de Oct. de 2015
Given the error and that load returned a double array, what follows was a logical next step--
>> load timestamps.mat
>> all(isfinite(Time))
ans =
0
>> any(isnan(Time))
ans =
1
>> sum(isnan(Time))
ans =
434
>> Time(isnan(Time))=[]; % ok, so remove those and...
>> ts=datestr(Time); % now completes as expected...
>>
  1 comentario
dpb
dpb el 22 de Oct. de 2015
Of course, this doesn't answer the question as to how you generated the NaN entries, of course; you'll have to research that issue.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion 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