Compiling with function with MATLAB coder leads to filesystem error

Hi,
I am running into an issue where when I use the MATLAB Coder to compile a function in MEX, once the file is created and the Coder is attempting to verify the function, it returns an error. When I run my code calling the MEX function, I get the following error message:
fl:filesystem:AccessDenied
Additionally, if I try to delete the file in the Current Folder window, it just stays there and doesn't get deleted. I would appreciate any insight as to solutions for this.
Not Sure what additional information might be useful But I'll be sure to append it below as things get requested.

7 Comments

You do not have have permission to write in that directory. This can happen especially with Windows if you are trying to write into a subdirectory of where matlab is installed.
The function is being compiled in my project's folder which isn't in any MATLAB installation directory (it's actually on a USB, which I know is not an issue since I've generated MEX files succesfully on it before).
When you go to delete and are denied:
  • have you tried "clear all"?
  • have you tried quiting matlab and re-entering?
  • have you tried deleting from your operating system file browser?
I have tried all of these and none seem to work. The only time I am able to delete them is when I restart my computer. However, if I try to run the function again, the same problem occurs.
that suggests to me that there might be a process (other than the matlab executable) hanging around that is accessing the file, so it is not writable because it is in use. Some exploration with Task Manager might be useful.
I have tried to see what is blocking the file to no avail. I attempted to research the link and follow the instructions, but I was unable to delete any of the files or free them from another process (I was unable to see if another process was blocking them). I guess the issue now is why is MATLAB generating a file that can't be accessed?

Sign in to comment.

Answers (1)

Hi Paul,
I understand that you are facing the error while using the MATLAB Coder to compile a function in MEX.The error message fl:filesystem:AccessDenied suggests that MATLAB is encountering a permissions issue when trying to access or modify a file on the file system. This could be due to various reasons, such as the file being in use by another process, insufficient user permissions, or the file being marked as read-only.
Here are some steps you can take to troubleshoot and resolve the issue:
  1. Check File Permissions: Ensure that you have the necessary permissions to read, write, and execute the file. You can check the file properties and modify the permissions if needed.
  2. Close Other Programs: Make sure that no other applications or instances of MATLAB are using the file. Sometimes, a file may be locked because it is open in another program.
  3. Use Administrator Privileges: Try running MATLAB as an administrator (if you are on Windows) to ensure it has the permissions needed to access the file.
  4. Check for Read-Only Attribute: Verify that the file is not set to read-only. You can change this by right-clicking on the file, selecting Properties, and unchecking the Read-only option.
  5. Use Command Line to Delete: If you are unable to delete the file from within MATLAB, you can try using the command line. On Windows, you can use the Command Prompt with administrator privileges, and on macOS/Linux, you can use the Terminal.
  6. Check for Antivirus Interference: Sometimes antivirus software can interfere with file operations. Temporarily disable your antivirus and try again.
  7. Check MATLAB Path: Ensure that the MATLAB path is set correctly and that it does not include any folders for which you do not have proper access permissions.
When trying to resolve file access issues, proceed with caution, especially when using commands that can permanently delete files or alter permissions.
Hope this helps.
Thank you

Categories

Products

Release

R2021b

Asked:

on 14 Apr 2022

Answered:

on 29 Dec 2023

Community Treasure Hunt

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

Start Hunting!