Undefined function or variable 'filename'

24 views (last 30 days)
Em
Em on 28 Dec 2020
Commented: Cris LaPierre on 1 Jan 2021
Hi everyone,
Whenever I try to execute my .m file, I get the error message popping up: "Undefined function or variable 'filename' ".
I've recently reorganised my files and moved this particular file to a new location. I have added the file to the path again and I'm in the correct directory.
Does anyone know what could be causing this now?

Answers (1)

Cris LaPierre
Cris LaPierre on 28 Dec 2020
The error means you are using filename as a variable or function but have not created it or defined it yet. Given the choice of name, I suspect you intended it to be a variable. Look at your code (the error message will tell you exactly what line) and see if you ever assign a value to filename.
If that's not it, we can't do much more than guess unless you are willing to share your code. Also, it's best to share the full error message (copy/paste all the red text) here.
  6 Comments
Cris LaPierre
Cris LaPierre on 1 Jan 2021
It looks like your current directory is not the same as the one the script is in. Your current directory is indicated in the top left as well as the bread crumb running just below the toolbar ribbon. Try navigating one step further by opening the "Au1 75mms 42mW 3 line thickness' folder.
If you press the green Run button in the toolbar, that should also prompt you to change your current folder to the one containing the script.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!