Error in reading a file ''index out of bounds because numel(p)=1"

1 次查看(过去 30 天)
Hello. The code for extracting data from SP3(Standard Product) type of file will do it for igs11484.sp3 but it won't for igs17311.sp3 (I have attached both) and I can't figure why. When I call the function for igs17311.sp3 i get this error: ''Attempted to access p(2); index out of bounds because numel(p)=1"
The code is:
function [Xs,Ys,Zs,Ts] = read_sp3(sp3file,sv);
%Example: [Xs,Ys,Zs,Ts] = read_sp3('igs11484.sp3',1)
fid=fopen(sp3file,'r');
Xs=[]; Ys=[]; Zs=[]; Ts=[];
while 1
line = fgetl(fid);
if ~isstr(line), break, end
if (line(1)=='*')
[t] = sscanf(line, '%c %d %d %d %d %d %f');
end
if (line(1)=='P')
[p] = sscanf(line, '%c %d %lf %lf %lf %f');
if (p(2) == sv)
Xs = [Xs;p(3)]; Ys = [Ys;p(4)]; Zs = [Zs;p(5)]; Ts = [Ts;t(5)*3600+t(6)*60+t(7)];
end
end
end
fclose(fid);

采纳的回答

Jan
Jan 2014-4-14
编辑:Jan 2014-4-14
This is a job for the debugger. Type this in the command window:
dbstop if error
Then start the program again. It stops when the error occurs. Now check the contents of the variable line.
Another very easy method to check what's going on is to display the contents of the currently processed line: Simply omit the semicolon after line = fgetl(fid). Then the last shown line contains the problem.
Debugging locally is more efficient than asking the forum members to do so.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Debugging and Analysis 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by