MATLAB: Fscanf problem with reading txt data.

fscanf

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 =
[]

Best Answer

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