Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
fopen > permission denied?

Subject: fopen > permission denied?

From: Joshua

Date: 17 Sep, 2008 04:15:02

Message: 1 of 6

Hi,

I want to run the code below but I get a "permission denied" message. I guess it the problem is with the fopen command... What does that mean and how can I fix it? Any help is greatly appreciate. Thanks

A=input ('Enter the lattice constant a ')
B=input ('Enter the lattice constant b ')
C=input ('Enter the lattice constant c ')
D=input ('Enter the lattice constant Beta ')
%G=[A^2 0 A*C*cos(D*(pi/180)); 0 B^2 0; A*C*cos(D*(pi/180)) 0 C^2]
%F=[ 1/((A^2)*(sin(D*(pi/180)))^2) 0 -cos(D*(pi/180))/(A*C*(sin(D*(pi/180)))^2); 0 1/B^2 0; -cos(D*(pi/180))/(A*C*(sin(D*(pi/180)))^2) 0 1/((C^2)*(sin(D*(pi/180)))^2)]
%E=G*F
g = 0;
M = cell(567,3);
d_spacing=zeros(567,1);

    for i=1:6
        for j=0:9
            for k=0:9
                if g==567
                    break, end
                    g = g + 1;
                    M{g}=[i j k];
                    d_spacing(g)=1/(((1/(A^2))*(i^2)/(sin(D*(pi/180))^2) +...
                    ((j^2)/(B^2)) + (1/(C^2))*(k^2)/(sin(D*(pi/180))^2) - ...
                    (2*i*k*cos(D*(pi/180)))/(A*C*(sin(D*(pi/180))^2)))^.5);
            
            end
        end
    end
[dval, didx] = sort(d_spacing, 'descend');
mreorder = cell2mat(M(didx));
[fid, message] = fopen('work.txt', 'w');
if fid < 0
disp(message);
else
fprintf(fid, '%g\t\t\t%3d %3d %3d\n', d_spacing, mreorder .');
end

Subject: fopen > permission denied?

From: Rodney Thomson

Date: 17 Sep, 2008 06:36:01

Message: 2 of 6

"Joshua " <jjgarvin6@yahoo.com> wrote in message <gaq086$585$1@fred.mathworks.com>...
> Hi,
>
> I want to run the code below but I get a "permission denied" message. I guess it the problem is with the fopen command... What does that mean and how can I fix it? Any help is greatly appreciate. Thanks
>

One thing I've noticed is that you are not closing the file handle after use. This could be the problem. Do fclose(fid) at the end of your function.

Do a call to fclose('all') to close all open file handles or Restart MATLAB.

Aside from that, try to open the file using notepad / vim and see if its read only?

Rod

--
http://iheartmatlab.blogspot.com

Subject: fopen > permission denied?

From: Baran Aydogan

Date: 17 Sep, 2008 09:45:03

Message: 3 of 6

If you are using Matlab in Unix, maybe you do not have the "write" permission for the drive/folder.
Did you try creating any file on the same folder? If it is the folder that you do not have write permission then change rights with "chmod" command.
If it is the whole drive then it is probably not mounted correctly then you need to modify your "etc/fstab"

"Joshua " <jjgarvin6@yahoo.com> wrote in message <gaq086$585$1@fred.mathworks.com>...
> Hi,
>
> I want to run the code below but I get a "permission denied" message. I guess it the problem is with the fopen command... What does that mean and how can I fix it? Any help is greatly appreciate. Thanks
>
> A=input ('Enter the lattice constant a ')
> B=input ('Enter the lattice constant b ')
> C=input ('Enter the lattice constant c ')
> D=input ('Enter the lattice constant Beta ')
> %G=[A^2 0 A*C*cos(D*(pi/180)); 0 B^2 0; A*C*cos(D*(pi/180)) 0 C^2]
> %F=[ 1/((A^2)*(sin(D*(pi/180)))^2) 0 -cos(D*(pi/180))/(A*C*(sin(D*(pi/180)))^2); 0 1/B^2 0; -cos(D*(pi/180))/(A*C*(sin(D*(pi/180)))^2) 0 1/((C^2)*(sin(D*(pi/180)))^2)]
> %E=G*F
> g = 0;
> M = cell(567,3);
> d_spacing=zeros(567,1);
>
> for i=1:6
> for j=0:9
> for k=0:9
> if g==567
> break, end
> g = g + 1;
> M{g}=[i j k];
> d_spacing(g)=1/(((1/(A^2))*(i^2)/(sin(D*(pi/180))^2) +...
> ((j^2)/(B^2)) + (1/(C^2))*(k^2)/(sin(D*(pi/180))^2) - ...
> (2*i*k*cos(D*(pi/180)))/(A*C*(sin(D*(pi/180))^2)))^.5);
>
> end
> end
> end
> [dval, didx] = sort(d_spacing, 'descend');
> mreorder = cell2mat(M(didx));
> [fid, message] = fopen('work.txt', 'w');
> if fid < 0
> disp(message);
> else
> fprintf(fid, '%g\t\t\t%3d %3d %3d\n', d_spacing, mreorder .');
> end

Subject: fopen > permission denied?

From: Walter Roberson

Date: 17 Sep, 2008 14:33:38

Message: 4 of 6

Rodney Thomson wrote:
> "Joshua " <jjgarvin6@yahoo.com> wrote in message <gaq086$585$1@fred.mathworks.com>...

>> I want to run the code below but I get a "permission denied" message.

> One thing I've noticed is that you are not closing the file handle after use.
> This could be the problem. Do fclose(fid) at the end of your function.

I agree. On MS Windows, if the file is already open (for reading or writing)
by any program (including the same program, e.g., because it was not closed)
then Windows will deny the request to open it for write access.

--
Q = quotation(rand);
if isempty(Q); error('Quotation server filesystem problems')
else sprintf('%s',Q), end

Subject: fopen > permission denied?

From: Miguel Concha

Date: 3 Aug, 2012 16:56:24

Message: 5 of 6

I have a similar problem... but i cant create any file.
i have tryed with

[a,b]=fopen('whatever.txt', 'w')

with a lot of diferents 'whatever' and i keep geting the same message:

a =
    -1
b =
Permission denied

any idea of what is happening?



"Baran Aydogan" wrote in message <gaqjiv$62p$1@fred.mathworks.com>...
> If you are using Matlab in Unix, maybe you do not have the "write" permission for the drive/folder.
> Did you try creating any file on the same folder? If it is the folder that you do not have write permission then change rights with "chmod" command.
> If it is the whole drive then it is probably not mounted correctly then you need to modify your "etc/fstab"
>
> "Joshua " <jjgarvin6@yahoo.com> wrote in message <gaq086$585$1@fred.mathworks.com>...
> > Hi,
> >
> > I want to run the code below but I get a "permission denied" message. I guess it the problem is with the fopen command... What does that mean and how can I fix it? Any help is greatly appreciate. Thanks
> >
> > A=input ('Enter the lattice constant a ')
> > B=input ('Enter the lattice constant b ')
> > C=input ('Enter the lattice constant c ')
> > D=input ('Enter the lattice constant Beta ')
> > %G=[A^2 0 A*C*cos(D*(pi/180)); 0 B^2 0; A*C*cos(D*(pi/180)) 0 C^2]
> > %F=[ 1/((A^2)*(sin(D*(pi/180)))^2) 0 -cos(D*(pi/180))/(A*C*(sin(D*(pi/180)))^2); 0 1/B^2 0; -cos(D*(pi/180))/(A*C*(sin(D*(pi/180)))^2) 0 1/((C^2)*(sin(D*(pi/180)))^2)]
> > %E=G*F
> > g = 0;
> > M = cell(567,3);
> > d_spacing=zeros(567,1);
> >
> > for i=1:6
> > for j=0:9
> > for k=0:9
> > if g==567
> > break, end
> > g = g + 1;
> > M{g}=[i j k];
> > d_spacing(g)=1/(((1/(A^2))*(i^2)/(sin(D*(pi/180))^2) +...
> > ((j^2)/(B^2)) + (1/(C^2))*(k^2)/(sin(D*(pi/180))^2) - ...
> > (2*i*k*cos(D*(pi/180)))/(A*C*(sin(D*(pi/180))^2)))^.5);
> >
> > end
> > end
> > end
> > [dval, didx] = sort(d_spacing, 'descend');
> > mreorder = cell2mat(M(didx));
> > [fid, message] = fopen('work.txt', 'w');
> > if fid < 0
> > disp(message);
> > else
> > fprintf(fid, '%g\t\t\t%3d %3d %3d\n', d_spacing, mreorder .');
> > end

Subject: fopen > permission denied?

From: Steven_Lord

Date: 3 Aug, 2012 17:20:04

Message: 6 of 6



"Miguel Concha" <miguel_cds@hotmail.com> wrote in message
news:jvgvro$gmk$1@newscl01ah.mathworks.com...
> I have a similar problem... but i cant create any file.
> i have tryed with
> [a,b]=fopen('whatever.txt', 'w')
>
> with a lot of diferents 'whatever' and i keep geting the same message:
>
> a =
> -1
> b =
> Permission denied
>
> any idea of what is happening?

Does whatever.txt exist? If it exists, is it read-only? If it doesn't exist,
do you have write permissions to the directory in which you're trying to
create the file?

Try CDing to the temporary directory (probably something like /tmp for Linux
or Mac or c:\temp for Windows) and try creating the file there. If the
problem goes away, you're probably trying to write somewhere you don't have
permission to do so.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us