problem in reading datetime

1 次查看(过去 30 天)
lina
lina 2015-6-21
回答: dpb 2015-6-21
HI ALL
I Got a problem in reading string data file, the error is
??? Error using ==> textscan Invalid file identifier. Use fopen to generate a valid file identifier.
and the command which I used is
fid=fopen('ARBY STARL 170310-200514 LT Edited_OBS TIDES 6mins.dat','r','n','ARAB');
s=textscan(fid,'%{dd MMMM yyyy hh:mm}D %f %f','DateLocale','Delimiter',',');
fclose(ARBY STARL 170310-200514 LT Edited_OBS TIDES 6mins);
finally, my data type is
31 May 2012 04:20,02.650
31 May 2012 04:25,02.640
31 May 2012 04:30,02.630
31 May 2012 04:35,02.630
anyone can help?

回答(1 个)

dpb
dpb 2015-6-21
The file wasn't opened successfully as the error says...use the alternate return to find out additional information on why...
[fid,msg]=fopen('ARBY STARL 170310-200514 LT Edited_OBS TIDES 6mins.dat','r','n','ARAB')
and see what the error message is for hints. I note the character code is not in the listed options so while Matlab will not error it will warn and may or may not provide a correct interpretation. I'd suggest unless there's a known reason, simply use the defaults other than for file permission although the most likely cause for fopen to fail is that the file is not located on the path and so simply isn't found. But, I'd still suggest
[fid,msg]=fopen('ARBY STARL 170310-200514 LT Edited_OBS TIDES 6mins.dat','rt')
as first go and check the returned handle is valid before going on to try to read anything 'cuz "it ain't agonna' work" until it is (valid that is).

类别

Help CenterFile Exchange 中查找有关 Oceanography and Hydrology 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by