Error using xlsread (line 129). File name must be a string or character vector.

20 views (last 30 days)
I am getting this error when submitting my answer to Matlab Grader.
Error using xlsread (line 129)
File name must be a string or character vector.
Error in xlsxdatatostructurearray>dependentdata (line 151)
[num,txt,raw] = xlsread(CurrentSheet);
When I do class(CurrentSheet) it returns 'char'.
  1 Comment
Cameron Tiegs
Cameron Tiegs on 31 May 2020
Edited: Cameron Tiegs on 31 May 2020
The contents of CurrentSheet is cycled through each excel file that begins with AerodynamicData. So for one instance CurrentSheet will have a value of, CurrentSheet = 'AerodynamicData_Cm_BodyFlap.xlsx'

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 31 May 2020
What happens if you click "Run Function" instead of Submit?
Your code seems to run fine in MATLAB. I also created a problem in MATLAB Grader using the files you shared. It also ran without error. In fact, the only way I generate the exact same error message is if I do something like this:
[num,txt,raw] = xlsread(5);
When your function is assessed in MATLAB Grader, the code for calling the function can be different that what you see in the "Code to call your function" section (this section is so you can test that your function is working before submitting). Typically, the instructor will test the correctness of your function using different inputs. This seems to be the case under which you are getting an error.
Without more information about the actual test inputs, there is little we can do to help. I suggest reaching out to your instructor directly.

More Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 31 May 2020
Your codes are workign very well. You'd need to have all of your data files and scripts in one directory. That is it.

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!