empty array size is stuck on 1x3

조회 수: 1 (최근 30일)
Patrick Connolly
Patrick Connolly 2021년 10월 26일
편집: per isakson 2021년 10월 26일
%Start with an empty matrix
data=[];%Handle to open file
fileID=fopen('Track-16.gpx','r');
%Skip the first 14 lines
fscanf(fileID,'\n\n\n\n\n\n\n\n\n\n\n\n\n\n');
%Scan through until the end of file(feof). Specification low level IO.
%Result transposed and formatted into single matrix
while ~feof(fileID)
nextrow=fscanf(fileID, '%*s lat="%f" lon="%f">\n <ele>%f</ele>\n <time>2013-01-19T%f:%f:%f</time>\n');
nextrow=nextrow';
data=[data;nextrow];
end
fclose(fileID)
%Separating data file into separate vectors.
latitude=[data(1:end,1)];
longitude=[data(1:end,2)];
elevation=[data(1:end,3)];
hours=[data(1:end,4)];
minutes=[data(1:end,5)];
seconds=[data(1:end,6)];
THis is my error
Index in position 2 exceeds array bounds. Index must not exceed 3.
Error in test6 (line 19)
hours=[data(1:end,4)];

답변 (2개)

per isakson
per isakson 2021년 10월 26일
편집: per isakson 2021년 10월 26일
Try replace
fscanf(fileID,'\n\n\n\n\n\n\n\n\n\n\n\n\n\n');
by
for jj = 1 : 14
fgetl( fileID );
end
fscanf(fileID,'\n\n\n\n\n\n\n\n\n\n\n\n\n\n'); affects the current location of the position pointer in the specified file for blank lines only. (Test with ftell() .) Does the file starts with fourteen blank lines?

Sean de Wolski
Sean de Wolski 2021년 10월 26일
You may want to look at gpxread. Read GPX file - MATLAB gpxread (mathworks.com)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by