Azzera filtri
Azzera filtri

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

2 visualizzazioni (ultimi 30 giorni)
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);

Risposta accettata

Jan
Jan il 14 Apr 2014
Modificato: Jan il 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.

Più risposte (0)

Categorie

Scopri di più su Debugging and Analysis in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by