What is wrong with my Matlab code? Index out of bounds [closed]
I'm trying to read in a text file that contains nmea strings! But I get
??? Attempted to access y(1); index out of bounds because numel(Longitude)=0.
Error in ==> filter at 16
Loc(:,i)=coordinates(x(i),y(i))';
filter.m
clear all
A=textread('xxx\x.txt','%s','headerlines',1);
for i=1:30;
n=2*i-1;
A(i)=A(n);
end
b=A(1:30,:);
c=char(b);
x=c(:,17:24);
y=c(:,28:36);
I can't figure out why it is wrong?!!
You cut out the wrong part of the string and end up with the ,N,
part in the beginning (and also no decimals). I believe you want
Longitude=c(:,31:42);%Extract Longitude Array
Longitude=c(:,28:36);%Extract Longitude Array
My guess is that c(:,28:36)
is empty which implies A
might be empty too.
A
is empty. Use TEXTSCAN instead:
>> fid = fopen('C:\Users\myself\Desktop\2.txt', 'rt'); >> A = textscan(fid, '%s'); >> A = A{1}; >> fclose(fid);
精彩评论