How can I read a .txt file with out the header?

2 ビュー (過去 30 日間)
cob
cob 2014 年 10 月 6 日
編集済み: Azzi Abdelmalek 2014 年 10 月 7 日
Hi, I have several files for a different points. The file name is a number like this:
C:\Users\cborba\Documents\Tides\10513.txt
I need get the latitude of each one(line 4 from the header) and read the file without the header (starting from line 12). How can I do this?
Thanks

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 10 月 6 日
fid = fopen(C:\Users\cborba\Documents\Tides\10513.txt');
line1 = fgetl(fid);
res=[];
while ischar(line1)
res{end+1,1} =line1
line1 = fgetl(fid);
end
fclose(fid);
latitude=regexpi(res{4},'(?<=LATITUDE).+','match')
data=res(12:end)
  2 件のコメント
cob
cob 2014 年 10 月 7 日
Thaks Azzi for your help. Could you help a little more? I did exactly that you said and I get a variable data that's looks like: '17/11/1977 04:00,326,' and a variable latitude that's looks like: 01º,30'.0,S. How can I split the variable data into 2 others variables like date (17/11/1977 04:00) and hight (326). And how can I convert the latitude to decimals degree (-1.50)? Thanks a lot
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 10 月 7 日
編集済み: Azzi Abdelmalek 2014 年 10 月 7 日
fid = fopen('10513.txt');
line1 = fgetl(fid);
res=[];
while ischar(line1)
res{end+1,1} =line1
line1 = fgetl(fid);
end
fclose(fid);
latitude=regexpi(res{4},'(?<=LATITUDE).+','match')
data=res(12:end)
date=cellfun(@(x) x{1},regexp(data,'.{16}','match'),'un',0)
hight=str2double(cellfun(@(x,y) regexp(x,['(?<=' y ').+'],'match'),data,date))

サインインしてコメントする。

その他の回答 (1 件)

the cyclist
the cyclist 2014 年 10 月 6 日
One possibility is to use the Import Tool, available on the Home tab of the Toolstrip of the Command Window. This allows you to specify the exact spreadsheet locations you want to import.

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by