Timestamp not converting to a string
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposte (1)
dpb
il 22 Ott 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 Commento
dpb
il 22 Ott 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.
Vedere anche
Categorie
Scopri di più su Data Type Conversion in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!