0
$\begingroup$

I am trying to use the diary function in Matlab:

delete task1.txt 
diary task1.txt
echo on
format long
b = 1:c;
x = 10.^(-b); 
y = sin(x)./x;
echo off
diary off
end

When I run the script I get the following error:

"Cannot open file: permission denied"

How can I enable the permission in the script?

$\endgroup$
1
  • $\begingroup$ I'm voting to close this question as off-topic because it is about file permissions. $\endgroup$
    – Paul
    Mar 29, 2016 at 15:20

2 Answers 2

1
$\begingroup$

This almost certainly means that you do not have write permissions in the current working directory or task1.txt already exists and you do not have write permissions for that file. This causes an error when MATLAB tries to create or open the file task1.txt. If this is the case, you need to use your operating system's tools to change the permissions for that directory. For example, you can likely right click on the relevant folder or file and then edit the properties to change the permissions.

You can view the current working directory using the pwd command in MATLAB.

$\endgroup$
3
  • $\begingroup$ Just one thing to add to this answer; if you want to get around this (and you are starting Matlab from the Linux command line), you can simply do a "sudo matlab" to push through the permission issues. For example, I cannot permanently change the PATH variable in matlab without doing this since it lives up in /usr/local/ rather than under my home directory. $\endgroup$ Jul 22, 2014 at 5:06
  • $\begingroup$ @TylerOlsen I would strongly discourage running MATLAB as root (e.g. via sudo matlab). Not only for safety/security, this will also make root the owner of any files you write which is probably not desired. If you want to "permanently" change the path variable, it's better to do so in a startup.m file in your user's MATLAB directory. Permissions are a fundamental part of Unix type operating systems and it's not typically a great idea to just force your way through as root. $\endgroup$ Jul 22, 2014 at 16:21
  • $\begingroup$ Good point. It was a very frustrated fix that I used a while ago. Thank you for telling me about the startup.m file! This is clearly the right way to do it. $\endgroup$ Jul 22, 2014 at 18:44
-1
$\begingroup$

The solution is here for windows machine.

Type first >>pwd

then you will see the path of the matlab folder , for example,

C:\Program Files\MATLAB\R2012a\bin

Right click on bin file and choose properties and then "security", then "Edit" to change the permission to "Allow" for all Users, click oK, and you can go back to matlab and test it.

Thanks M Merdan

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.