Timestamp not converting to a string

4 次查看(过去 30 天)
saadatnk8
saadatnk8 2015-10-22
评论: dpb 2015-10-22
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

回答(1 个)

dpb
dpb 2015-10-22
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 个评论
dpb
dpb 2015-10-22
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by