Timestamp not converting to a string

4 vues (au cours des 30 derniers jours)
saadatnk8
saadatnk8 le 22 Oct 2015
Commenté : dpb le 22 Oct 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

Réponses (1)

dpb
dpb le 22 Oct 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 commentaire
dpb
dpb le 22 Oct 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.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by