필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Sebastian Ciuban
Sebastian Ciuban 2014년 4월 14일
댓글: Sebastian Ciuban 2014년 4월 14일
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