菜鸟求助!!MATLAB错误 Index exceeds matrix dimensions.

ttjane 2010-03-20 01:34:53
j=1;
[filename,filepath]=uigetfile('*.txt','Select Input file');
file = [filepath,filename];
fid = fopen(file,'rt');
if fid == -1
('Error opening the file')
end
while 1
nextline = fgetl(fid); %读第一行
DAY= nextline(1:2)
D(i)=str2num(DAY)
MONTH = nextline(4:6)
j=j+1;
if ~isstr(nextline), break, end %读到最后跳出
end

打开的文件内容为 20 Oct 2008
读数据正确 但总是出现错误提示:
??? Index exceeds matrix dimensions.

Error in ==> xishu at 10
DAY= nextline(1:2)
到底是为么事??
...全文
2265 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
ttjane 2010-04-08
  • 打赏
  • 举报
回复
谢谢大家 已经搞定了
文件最后一行有空行
去掉就ok了
老何 2010-03-24
  • 打赏
  • 举报
回复
[filename,filepath]=uigetfile('*.txt','Select Input file');
file = [filepath,filename];
fid = fopen(file,'rt');
if fid == -1
('Error opening the file')
end

txtline=fgetl(fid);

while ischar(txtline)
disp(txtline)
txtline=fgetl(fid);
end
fclose(fid);



要保持好的编程习惯每次打开文件不要忘了关闭
only_lonely 2010-03-22
  • 打赏
  • 举报
回复
尾随朵朵而来~
DAY= nextline(1:2)
参数是否错误? nextline(1:2) -> nextline(1,2) (我瞎猜的哈~完全不晓得这是什么语言~)
linmei19840721 2010-03-22
  • 打赏
  • 举报
回复
菜鸟帮菜鸟顶……

3,422

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 其他开发语言
社区管理员
  • 其他开发语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧