开发者

What is wrong with my Matlab code? Index out of bounds [closed]

开发者 https://www.devze.com 2023-03-27 03:17 出处:网络
开发者_运维百科 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not g
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.

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);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号