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

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

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

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.

1 Comment

I get no errors when I "Run Function". Thank you, I have emailed my lecturer now.

Sign in to comment.

More Answers (1)

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

Community Treasure Hunt

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

Start Hunting!