empty array size is stuck on 1x3

1 次查看(过去 30 天)
%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