empty array size is stuck on 1x3
古いコメントを表示
%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
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
2021 年 10 月 26 日
0 投票
カテゴリ
ヘルプ センター および File Exchange で Resizing and Reshaping Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!