Undefined function or variable 'filename'

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 (2)

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

Em
Em on 28 Dec 2020
Edited: Em on 28 Dec 2020
Thanks for your suggestion but actually I was trying to run exactly the same code as before - I just moved all the files around on my laptop. I've made no reference to the name in the .m file itself, and every file I run seems to give the same error message.
The full error message is
Undefined function or variable 'Au175mms42mW3linesPLOTS'.
where 'Au175mms42mW3linesPLOTS' is the name of my file.
Cheers,
Em
Where does this file reside in reference to your current folder?
The file is in my current folder. Should I send some screenshots of anything? Thanks for your help
A screenshot of your entire screen might be helpful. Make sure it shows the file you are trying to run open in the editor, your current folder set correctly, with this missing function visible, and the command window displaying the error message.
Make sure in the editor we can see the line of code that is causing the error, along with as much of the preceding code as possible.
If I take the code and paste it into the command window, then it runs fine. Also I tried running an older program and it worked fine. Normally when you have the right workspace loaded and 'add the program to path' then it works fine, I can't see what the difference could be here.
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.

If the name of the folder uses special character, then you get this error. In my case, I saved my matlab m file in a folder that uses '*'. I removed the '*' from the name and it worked for me.

Categories

Products

Release

R2018a

Asked:

Em
on 28 Dec 2020

Answered:

on 1 Nov 2023

Community Treasure Hunt

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

Start Hunting!