empty array size is stuck on 1x3
1 view (last 30 days)
Show older comments
%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)];
0 Comments
Answers (2)
per isakson
on 26 Oct 2021
Edited: per isakson
on 26 Oct 2021
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?
0 Comments
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!