Timestamp not converting to a string

4 Ansichten (letzte 30 Tage)
saadatnk8
saadatnk8 am 22 Okt. 2015
Kommentiert: dpb am 22 Okt. 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

Antworten (1)

dpb
dpb am 22 Okt. 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 Kommentar
dpb
dpb am 22 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by