MATLAB Answers

My code keeps telling me with an error "Index Exceeds Array Bounds" HELP PLEASE

조회 수: 2(최근 30일)
Mohammad Junayed
Mohammad Junayed 25 Oct 2018
편집: OCDER 25 Oct 2018
please help me to solve the error;
(i attached the file)

  댓글 수: 2

Kevin Chng
Kevin Chng 25 Oct 2018
post the relevant code here, which line cause error.
Mohammad Junayed
Mohammad Junayed 25 Oct 2018
Error using feof Invalid file identifier. Use fopen to generate a valid file identifier.
Error in MainTest (line 56) while ~feof(f)

댓글을 달려면 로그인하십시오.

채택된 답변

OCDER 25 Oct 2018
편집: OCDER 25 Oct 2018
At line 54:
  • You cannot read a .xlsx file properly via fopen. Use xlsread instead.
  • You should define "Path" variable as directory path, and "File" variable as the file. Currently, ASDPath is the user.xlsx, which is a file.
  • Use the full path to a file, and not just the relative path to current working directory. fullfile(ASDPath, ASDFile), where " ASDPath" should be the "path" todirectory, and " ASDFile" should be the "file" ending with .xlsx
  • Add an error check after the fopen to help with debug
ASDPath = 'C:\User\Desktop\....\'; %PATH to your file
ASDFile = 'user.xlsx';
[NumData, StrData, AllData] = xlsread(fullfile(ASDPath, ASDFile));
[f, ErrMsg] = fopen(ASDPath, 'r'); %This won't work for xlsx file. okay for txt file.
assert(f > 0, ErrMsg); %If FID < 0, fopen failed. So this will tell you what the error is.

  댓글 수: 0

댓글을 달려면 로그인하십시오.

추가 답변(0개)


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by