fscanf problem with reading txt data.

28 ビュー (過去 30 日間)
sermet
sermet 2015 年 3 月 16 日
コメント済み: srt10 2021 年 2 月 11 日
fid = fopen('current.txt') %Open source file "current.txt"
NumSV = fscanf(fid, '%d') %Number of Satellites (PRN)
name = fgetl(fid)
[data, count] = fscanf(fid,'%f')
fclose(fid)
%I need to extract related information from current.txt file with using fscanf but it creates empty matrix like,
NumSV =
[]
  2 件のコメント
sermet
sermet 2015 年 3 月 16 日
I need to determine how many PRN exist in current.txt

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

採用された回答

Star Strider
Star Strider 2015 年 3 月 16 日
編集済み: Star Strider 2015 年 3 月 16 日
I would use textscan.
This works:
fidi = fopen('current.txt', 'rt');
NumSV = textscan(fidi, '%s%f', 'HeaderLines',1, 'EndOfLine','\r\n', 'Whitespace',' ', 'Delimiter',':');
strings = NumSV{1};
numeric = NumSV{2};
It reads in the entire file. The individual satellites are separated by NaN values in the ‘numeric’ vector, corresponding to the ‘******** Week 806 ...’ lines.
EDIT To count the number of satellites, count the number of NaN values in the ‘numeric’ vector:
NumberOfSatellites = size(isnan(numeric), 1);
When I ran my code with your file, the result was:
NumberOfSatellites =
20
  3 件のコメント
srt10
srt10 2021 年 2 月 11 日
Thanks for your reply. I understand now.

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

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by