MATLAB unable to find files

66 views (last 30 days)
Victor
Victor on 26 Oct 2025 at 0:02
Moved: dpb ungefär 9 timmar ago
I am working on a project and MATLAB fails to open files for me. I downloaded some .m files off of my OneDrive and they were perfectly fine and uncorrupted. Furthermore, I was able to view them in OneDrive without issue. When I downloaded the file and put it into the folder where I was working in, the file didn't open when I tried to double click it.
MATLAB told me it was unable to find the file despite the fact that it was in the folder I was working in and returned the correct path. When attempting to troubleshoot, I noticed that one recommendation was to have MATLAB use the default folder in Documents/MATLAB. Since that folder was in my OneDrive for some reason, I made a new one saved on my computer and tried to have MATLAB open to that upon start-up. MATLAB then told me the folder didn't exist when I tried to submit the new path.
Ultimately, I decided to copy the contents of the .m file and paste it into a new .m file created through MATLAB, which worked just fine. However, I cannot find the reason for the issue in the first place. I'd like some help figuring out what can be done.
  5 Comments
Victor
Victor ungefär 2 timmar ago
I'm not much of a computer guy so bear with me.
  1. The new folder is unlikely to have been hidden. I do not know how to hide folders.
  2. I put the new folder under my user profile for my laptop, in a relatively high level directory. I don't know how to determine if a folder has been hidden.
  3. MATLAB dir() did locate the files it failed to open.
  4. Not quite sure how to use that, but I was able to open the file with VS Code, so it did confirm the file exists where the GUI says it exists.
The download was just selecting the download button on OneDrive, as putting it right in my downloads folder. Not another OneDrive folder, mind you. I made sure to check, This is my personal machine and I like to use OneDrive as little as possible, mostly because I can't stand the headache of not knowing which files I actually have locally.
Image Analyst
Image Analyst 37 minuter ago
When you go to File Explorer and look at the One Drive source folder, does it have a white check mark in a green circle next to the file names.
This means you're telling OneDrive to always keep a local copy. If it's not checked then the only copy (if you haven't accessed the file in a while) will be on the OneDrive server in the cloud. And perhaps there's some kind of delay in downloading the file from the cloud from the time you try to paste it until it actually gets there. Click on the cloud in the lower left task tray of your task bar and see if it says "Your files are synced."
To make sure you always have files on your local hard or SS drive, right click on the folder that you want to always keep local and select "Always keep on this device". I think that should apply to all the files within the folder too. You should see green checkmark circles when it's done.

Sign in to comment.

Accepted Answer

Victor
Victor on 28 Oct 2025 at 20:40
Moved: Walter Roberson ungefär 20 timmar ago
RESOLVED! I managed to use addpath(genpath()) to the subfolder I wanted to work with and now MATLAB has managed to find the files on my computer. According to the person who gave me the advice, I'll have to run that line of code at the start of each session, but it worked.
Thank you to everyone who took the time to help.
  1 Comment
dpb
dpb on 28 Oct 2025 at 22:38
Moved: dpb ungefär 9 timmar ago
Read about <What is MATLAB search path?> and how to set an additional folder on startup. Or, you can use the Settings dialog to define and save the revised MATLABPATH. You definitely don't have to do this manually every time.
My general practice is to have a specific working directory for current work and add it to the top of the search path and have that saved

Sign in to comment.

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Products


Release

R2024b

Community Treasure Hunt

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

Start Hunting!