fscanf problem with reading txt data.

28 ビュー (過去 30 日間)
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')
%I need to extract related information from current.txt file with using fscanf but it creates empty matrix like,
NumSV =
  2 件のコメント
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 =
  3 件のコメント
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