reading specific parts of txt file

5 ビュー (過去 30 日間)
sermet 2015 年 8 月 22 日
編集済み: Walter Roberson 2015 年 8 月 22 日
[FileName,PathName] = uigetfile('*txt','Select the ionex file');
if FileName ~= 0
completename = fullfile(PathName, FileName);
head_lines = 0;
while 1
head_lines = head_lines+1;
line = fgets(data_2); %headers
answer = strfind(line,'EPOCH OF CURRENT MAP');
if ~isempty(answer)
head_lines_2=0; % the other remaining lines after headers
while 1
head_lines_2 = head_lines_2+1;
line_2 = fgets(data_2); %data parts
answer_2 = strfind(line_2,'END OF DATA');
if ~isempty(answer_2)
in txt file, "EPOCH OF CURRENT MAP" is the time of the data (which is 2 in trial.txt); LAT is latitude, LON1 and LON2 are first longitude and last longitude with 5 degrees incremental for each LAT/LON1/LON2/DLON/H. Numbers between LAT/LON1/LON2/DLON/H are data.
I need to write codes which find the two nearest LAT and LON in txt file w.r.t. the user's lat and lon for each "EPOCH OF CURRENT MAP" time.
for example, for "user_latitude=84.44" and "user_longitude=56.65"; two nearest LAT are 85, 82.50; two nearest LON are 55, 60 and four data of first "EPOCH OF CURRENT MAP" are 141 for LAT 82.50, LON 55, 147 for LAT 82.50, LON 60, 170 for LAT 85, LON 55, 174 for LAT 85, LON 60.
I tried to read with fgets function but only last line of data remains.
Thanks in advance.
  3 件のコメント
Walter Roberson
Walter Roberson 2015 年 8 月 22 日
One trick for you: When you use textscan(), the format you specify does not need to cover an entire line at a time. You have blocks that appear to be 4 lines of 16 followed by 1 line of 9: you can code that as a '%f' format with a repeat count of 73.
However, some of your values are in fixed-width fields, and those are difficult to handle properly with textscan(). You might want to modify for this purpose.


回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by