Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
index of out of bounds from txt
    조회 수: 5 (최근 30일)
  
       이전 댓글 표시
    
Guys, i simplified the problem The code is:
    name=['r9460.txt']
    fid=fopen(name,'r');
while ~(feof(fid)),
  head=fscanf(fid,'%d',11)
  if ~(isempty(head)),
    m=head(4)
  end
end
fclose(fid)
The txt is
    5  1994     4   8       9  14  40       0  31  16        5
            0.6            1
            0.6           25
            0.9            1
            3.5            4
            0.9            1
Matlab says Attempted to access head(4); index out of bounds because numel(head)=1.
Please, help me, i'm in your hands!
댓글 수: 0
답변 (1개)
  Andy
      
 2014년 2월 21일
        Hi Nicola,
head=fscanf(fid,'%d',11)
you are constantly changing the value of head, not incrementing it. Try: -
fid=fopen(name,'r');
x=1;
while ~(feof(fid)),
head(x)=fscanf(fid,'%d',11)
x=x+1;
if ~(isempty(head)),
  m=head(4)
end
end
fclose(fid)
댓글 수: 0
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

