从特定行读取文本文件

如何在 matlab 中读取包含以下文本的文本文件?

Port:              P988
Site:              Bournemouth
Latitude:          50.71433
Longitude:         -1.87486
Start Date:        01JUL2017-00.00.00
End Date:          31JUL2017-23.45.00
Contributor:       National Oceanography Centre, Liverpool
Datum information: The data refer to Admiralty Chart Datum (ACD)
Parameter code:    ASLVBG02 = Surface elevation (unspecified datum) of the water body by bubbler tide gauge (second sensor)
  Cycle    Date      Time    ASLVBG02   Residual  
 Number yyyy mm dd hh mi ssf         f          f 
     1) 2017/07/01 00:00:00     1.758M     0.046M 
     2) 2017/07/01 00:15:00     1.752M     0.045M 
     3) 2017/07/01 00:30:00     1.754M     0.055M 
     4) 2017/07/01 00:45:00     1.753M     0.064M 
     5) 2017/07/01 01:00:00     1.763M     0.081M 
     6) 2017/07/01 01:15:00     1.768M     0.088M 
     7) 2017/07/01 01:30:00     1.756M     0.074M 
     8) 2017/07/01 01:45:00     1.753M     0.067M 
     9) 2017/07/01 02:00:00     1.749M     0.060M 
    10) 2017/07/01 02:15:00     1.737M     0.051M 

我正在寻找阅读形式

1) 2017/07/01 00:00:00     1.758M     0.046M

向前。可以根据 ASLVBG02 绘制每天的时间。每天由 96 行组成。

am304

正如已经建议的那样,使用textscan. 根据您的采样日期,以下内容在 Octave 中运行良好:

% Open the file (replace by actual file name)
fid = fopen('test_file.txt');

% Read data with following format
% 1) 2017/07/01 00:00:00     1.758M     0.046M 
data = textscan(fid,'%d %c %f %c %f %c %f %f %c %f %c %f %f %c %f %c','HeaderLines',11);

% Close the file
fclose(fid);

% Re-arrange time data
yyyy = data{1,3};
MM = data{1,5};
dd = data{1,7};
hh = data{1,8};
mm = data{1,10};
ss = data{1,12};
date_time = datenum(yyyy,MM,dd,hh,mm,ss);

% Get ASLVBG02 data
ASLVBG02 = data{1,13};

% Plot the data
plot(date_time,ASLVBG02)
grid on
datetick('HH:MM:SS')
ylabel('ASLVBG02')

它产生以下情节:

在此处输入图片说明

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章