Error in reading a file ''index out of bounds because numel(p)=1"
2 views (last 30 days)
Show older comments
Sebastian Ciuban
on 14 Apr 2014
Commented: Sebastian Ciuban
on 14 Apr 2014
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);
0 Comments
Accepted Answer
Jan
on 14 Apr 2014
Edited: Jan
on 14 Apr 2014
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.
More Answers (0)
See Also
Categories
Find more on Debugging and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!