Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
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);

Respuesta aceptada

Jan
Jan el 14 de Abr. de 2014
Editada: Jan el 14 de Abr. de 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.

Más respuestas (0)

Categorías

Más información sobre Debugging and Analysis en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by